Skip to content

Commit

Permalink
Android: FINALLY fixed crash bug when clicking on options menu on Sam…
Browse files Browse the repository at this point in the history
…sung devices. The problem was due to setting a color to panelFullBackground instead of a drawable. However, the text is black instead of white... haven't found a solution in the last hour and a half. Sometimes Android makes you sweat for stupid reasons like that...

Related to issue #406.
  • Loading branch information
ycastonguay committed Oct 16, 2013
1 parent 5ba5a05 commit e5ae640
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 81 deletions.
36 changes: 23 additions & 13 deletions MPfm/MPfm.Android/Classes/Activities/MainActivity.cs
Expand Up @@ -22,8 +22,11 @@
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Content.Res;
using Android.Graphics;
using Android.Runtime;
using Android.Text;
using Android.Text.Style;
using Android.Views;
using Android.OS;
using Android.Views.Animations;
Expand Down Expand Up @@ -280,27 +283,31 @@ public override void OnBackPressed()
}
}

public override bool OnPrepareOptionsMenu(IMenu menu)
{
Console.WriteLine("MainActivity - OnPrepareOptionsMenu");
return true;
}
//public override bool OnPrepareOptionsMenu(IMenu menu)
//{
// Console.WriteLine("MainActivity - OnPrepareOptionsMenu");
// //MenuInflater.Inflate(Resource.Menu.main_menu, menu);
// //var menuItem = menu.Add(new Java.Lang.String("Test"));
// //menuItem.SetIcon(Resource.Drawable.actionbar_info);
// return true;
//}

public override bool OnCreateOptionsMenu(IMenu menu)
{
Console.WriteLine("MainActivity - OnCreateOptionsMenu");

// Crashed on all Samsung devices when using the options menu
//MenuInflater.Inflate(Resource.Menu.main_menu, menu);
//var menuItem = menu.Add(new Java.Lang.String("Test"));
//var menuItem2 = menu.Add(new Java.Lang.String("Test2"));
//var menuItem3 = menu.Add(new Java.Lang.String("Test3"));
MenuInflater.Inflate(Resource.Menu.main_menu, menu);
foreach (var option in _options)
{
var menuItem = menu.Add(new Java.Lang.String(option.Value));
{
// Unfortunately this crashes when selecting the item.
//var spannableString = new SpannableString(new Java.Lang.String(option.Value));
//spannableString.SetSpan(new ForegroundColorSpan(Color.White), 0, spannableString.Length(), 0);
//var menuItem = menu.Add(spannableString);

var menuItem = menu.Add(option.Value);
switch (option.Key)
{
case MobileOptionsMenuType.About:
//menuItem.SetShowAsAction(ShowAsAction.Never);
menuItem.SetIcon(Resource.Drawable.actionbar_info);
break;
case MobileOptionsMenuType.EqualizerPresets:
Expand All @@ -316,12 +323,15 @@ public override bool OnCreateOptionsMenu(IMenu menu)
menuItem.SetIcon(Resource.Drawable.actionbar_sync);
break;
case MobileOptionsMenuType.SyncLibraryCloud:
//menuItem.SetShowAsAction(ShowAsAction.Never);
menuItem.SetIcon(Resource.Drawable.actionbar_cloud);
break;
case MobileOptionsMenuType.SyncLibraryFileSharing:
//menuItem.SetShowAsAction(ShowAsAction.Never);
menuItem.SetIcon(Resource.Drawable.actionbar_share);
break;
case MobileOptionsMenuType.SyncLibraryWebBrowser:
//menuItem.SetShowAsAction(ShowAsAction.Never);
menuItem.SetIcon(Resource.Drawable.actionbar_earth);
break;
}
Expand Down
1 change: 1 addition & 0 deletions MPfm/MPfm.Android/MPfm.Android.csproj
Expand Up @@ -620,6 +620,7 @@
<AndroidResource Include="Resources\drawable-xhdpi\actionbar_playlist.png" />
<AndroidResource Include="Resources\drawable-xxhdpi\actionbar_playlist.png" />
<AndroidResource Include="Resources\drawable\carrouseldot.xml" />
<AndroidResource Include="Resources\drawable\optionsmenu.xml" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
Expand Down
28 changes: 28 additions & 0 deletions MPfm/MPfm.Android/Resources/Drawable/optionsmenu.xml
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- disabled -->
<item
android:state_enabled="false"
android:state_focused="true">
<shape>
<solid android:color="@color/actionbar" />
</shape>
</item>
<!-- pressed -->
<item android:state_pressed="true">
<shape>
<solid android:color="@color/actionbar" />
</shape>
</item>
<!-- focused -->
<item android:state_focused="true">
<shape>
<solid android:color="@color/actionbar" />
</shape>
</item>
<item>
<shape>
<solid android:color="@color/actionbar" />
</shape>
</item>
</selector>
139 changes: 74 additions & 65 deletions MPfm/MPfm.Android/Resources/Resource.Designer.cs

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

1 change: 1 addition & 0 deletions MPfm/MPfm.Android/Resources/Values/Colors.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="color_black">#000000</color>
<color name="white">#000000</color>
<color name="background">#20282E</color>
<color name="actionbar">#36454F</color>
<color name="actionbar_selected">#6D899B</color>
Expand Down

0 comments on commit e5ae640

Please sign in to comment.