Skip to content
This repository has been archived by the owner on Jan 13, 2018. It is now read-only.

Commit

Permalink
Fix for passing in a resource to set home button. Fixes #20.
Browse files Browse the repository at this point in the history
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
jamesmontemagno committed Mar 28, 2013
1 parent 43cd5bc commit c59b5a2
Show file tree
Hide file tree
Showing 19 changed files with 108 additions and 119 deletions.
9 changes: 2 additions & 7 deletions LegacyBar.Library/BarBase/LegacyBarActivity.cs
Expand Up @@ -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));
Expand Down
9 changes: 2 additions & 7 deletions LegacyBar.Library/BarBase/LegacyBarFragmentActivity.cs
Expand Up @@ -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));
Expand Down
8 changes: 2 additions & 6 deletions LegacyBar.Library/BarBase/LegacyBarListActivity.cs
Expand Up @@ -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)
{
Expand Down
4 changes: 0 additions & 4 deletions LegacyBar.Library/LegacyBar.Library.csproj
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion LegacyBar.Library/Properties/AndroidManifest.xml
@@ -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>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
41 changes: 3 additions & 38 deletions LegacyBar.Library/Resources/Resource.designer.cs

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

9 changes: 0 additions & 9 deletions LegacyBar.Library/Resources/Values/strings.xml
@@ -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>
4 changes: 2 additions & 2 deletions LegacyBar.Sample/FragmentTabActivity.cs
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion LegacyBar.Sample/HomeActivity.cs
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions LegacyBar.Sample/LegacyBar.Sample.csproj
Expand Up @@ -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>
Expand Down Expand Up @@ -272,4 +270,7 @@
<ItemGroup>
<AndroidResource Include="Resources\drawable-xhdpi\icon.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\values\strings.xml" />
</ItemGroup>
</Project>
33 changes: 29 additions & 4 deletions LegacyBar.Sample/OtherActivity.cs
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion LegacyBar.Sample/Properties/AndroidManifest.xml
@@ -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>
13 changes: 13 additions & 0 deletions LegacyBar.Sample/Resources/Menu/othermainmenu.xml
Expand Up @@ -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>

0 comments on commit c59b5a2

Please sign in to comment.