Skip to content

Commit

Permalink
Android: Fixed bug with orientation change on newer activities. Conve…
Browse files Browse the repository at this point in the history
…rted SyncFragment to SyncActivity.

Related to issue #406.
  • Loading branch information
ycastonguay committed Jun 29, 2013
1 parent ec7755a commit 6bb7ee7
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Collections.Generic;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Views;
using Android.OS;
using MPfm.Android.Classes.Navigation;
Expand All @@ -29,7 +30,7 @@

namespace MPfm.Android
{
[Activity(Label = "Equalizer Presets")]
[Activity(Label = "Equalizer Presets", ScreenOrientation = ScreenOrientation.Sensor, Theme = "@style/MyAppTheme", ConfigurationChanges = ConfigChanges.KeyboardHidden | ConfigChanges.Orientation | ConfigChanges.ScreenSize)]
public class EqualizerPresetsActivity : BaseActivity, IEqualizerPresetsView
{
private MobileNavigationManager _navigationManager;
Expand Down
21 changes: 19 additions & 2 deletions MPfm/MPfm.Android/Classes/Activities/PlayerActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.Threading.Tasks;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Support.V4.View;
using Android.Views;
using Android.OS;
Expand All @@ -39,12 +40,11 @@

namespace MPfm.Android
{
[Activity(Label = "Player")]
[Activity(Label = "Player", ScreenOrientation = ScreenOrientation.Sensor, Theme = "@style/MyAppTheme", ConfigurationChanges = ConfigChanges.KeyboardHidden | ConfigChanges.Orientation | ConfigChanges.ScreenSize)]
public class PlayerActivity : BaseActivity, IPlayerView
{
private bool _isPositionChanging;
private BitmapCache _bitmapCache;
private View _view;
private ImageView _imageViewAlbumArt;
private TextView _lblPosition;
private TextView _lblLength;
Expand Down Expand Up @@ -94,6 +94,16 @@ protected override void OnCreate(Bundle bundle)

// Match height with width (cannot do that in xml)
//_imageViewAlbumArt.LayoutParameters = new ViewGroup.LayoutParams(_imageViewAlbumArt.Width, _imageViewAlbumArt.Width);

if (bundle != null)
{
string state = bundle.GetString("key", "value");
Console.WriteLine("MainActivity - OnCreate - State is {0}", state);
}
else
{
Console.WriteLine("MainActivity - OnCreate - State is null");
}
}

protected override void OnStart()
Expand Down Expand Up @@ -144,6 +154,13 @@ protected override void OnDestroy()
base.OnDestroy();
}

protected override void OnSaveInstanceState(Bundle outState)
{
Console.WriteLine("PlayerActivity - OnSaveInstanceState");
base.OnSaveInstanceState(outState);
outState.PutString("key", DateTime.Now.ToLongTimeString());
}

public override bool OnOptionsItemSelected(IMenuItem item)
{
switch (item.ItemId)
Expand Down
3 changes: 2 additions & 1 deletion MPfm/MPfm.Android/Classes/Activities/PreferencesActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Collections.Generic;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Support.V4.View;
using Android.Views;
using Android.OS;
Expand All @@ -30,7 +31,7 @@

namespace MPfm.Android
{
[Activity(Label = "Preferences")]
[Activity(Label = "Preferences", ScreenOrientation = ScreenOrientation.Sensor, Theme = "@style/MyAppTheme", ConfigurationChanges = ConfigChanges.KeyboardHidden | ConfigChanges.Orientation | ConfigChanges.ScreenSize)]
public class PreferencesActivity : BaseActivity, IPreferencesView
{
private MobileNavigationManager _navigationManager;
Expand Down
145 changes: 145 additions & 0 deletions MPfm/MPfm.Android/Classes/Activities/SyncActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// Copyright © 2011-2013 Yanick Castonguay
//
// This file is part of MPfm.
//
// MPfm is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// MPfm is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Views;
using Android.OS;
using MPfm.Android.Classes.Navigation;
using MPfm.Library.Objects;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Navigation;
using MPfm.MVP.Views;
using MPfm.Player.Objects;

namespace MPfm.Android
{
[Activity(Label = "Sync", ScreenOrientation = ScreenOrientation.Sensor, Theme = "@style/MyAppTheme", ConfigurationChanges = ConfigChanges.KeyboardHidden | ConfigChanges.Orientation | ConfigChanges.ScreenSize)]
public class SyncActivity : BaseActivity, ISyncView
{
private MobileNavigationManager _navigationManager;

protected override void OnCreate(Bundle bundle)
{
Console.WriteLine("SyncActivity - OnCreate");
base.OnCreate(bundle);

_navigationManager = Bootstrapper.GetContainer().Resolve<MobileNavigationManager>();
SetContentView(Resource.Layout.Sync);
ActionBar.SetDisplayHomeAsUpEnabled(true);
ActionBar.SetHomeButtonEnabled(true);
}

protected override void OnStart()
{
Console.WriteLine("SyncActivity - OnStart");
base.OnStart();

// Since the onViewReady action could not be added to an intent, tell the NavMgr the view is ready
((AndroidNavigationManager)_navigationManager).SetSyncActivityInstance(this);
}

protected override void OnRestart()
{
Console.WriteLine("SyncActivity - OnRestart");
base.OnRestart();
}

protected override void OnPause()
{
Console.WriteLine("SyncActivity - OnPause");
base.OnPause();
}

protected override void OnResume()
{
Console.WriteLine("SyncActivity - OnResume");
base.OnResume();
}

protected override void OnStop()
{
Console.WriteLine("SyncActivity - OnStop");
base.OnStop();
}

protected override void OnDestroy()
{
Console.WriteLine("SyncActivity - OnDestroy");
base.OnDestroy();
}

public override bool OnOptionsItemSelected(IMenuItem item)
{
switch (item.ItemId)
{
case global::Android.Resource.Id.Home:
var intent = new Intent(this, typeof (MainActivity));
intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
this.StartActivity(intent);
this.Finish();
return true;
break;
default:
return base.OnOptionsItemSelected(item);
break;
}
}

#region ISyncView implementation

public Action<string> OnConnectDevice { get; set; }
public Action<string> OnConnectDeviceManually { get; set; }

public void SyncError(Exception ex)
{
RunOnUiThread(() => {
AlertDialog ad = new AlertDialog.Builder(this).Create();
ad.SetCancelable(false);
ad.SetMessage(string.Format("An error has occured in Sync: {0}", ex));
ad.SetButton("OK", (sender, args) => ad.Dismiss());
ad.Show();
});
}

public void RefreshIPAddress(string address)
{
}

public void RefreshDiscoveryProgress(float percentageDone, string status)
{
}

public void RefreshDevices(IEnumerable<SyncDevice> devices)
{
}

public void RefreshDevicesEnded()
{
}

public void SyncDevice(SyncDevice device)
{
}

#endregion

}
}
2 changes: 1 addition & 1 deletion MPfm/MPfm.Android/Classes/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override void OnCreate()
container.Register<IPitchShiftingView, PitchShiftingFragment>().AsMultiInstance();
container.Register<IUpdateLibraryView, UpdateLibraryFragment>().AsMultiInstance();
container.Register<IMobileLibraryBrowserView, MobileLibraryBrowserFragment>().AsMultiInstance();
container.Register<ISyncView, SyncFragment>().AsMultiInstance();
container.Register<ISyncView, SyncActivity>().AsMultiInstance();
container.Register<ISyncDownloadView, SyncDownloadFragment>().AsMultiInstance();
container.Register<ISyncMenuView, SyncMenuFragment>().AsMultiInstance();
container.Register<IEqualizerPresetsView, EqualizerPresetsActivity>().AsMultiInstance();
Expand Down
91 changes: 0 additions & 91 deletions MPfm/MPfm.Android/Classes/Fragments/SyncFragment.cs

This file was deleted.

14 changes: 14 additions & 0 deletions MPfm/MPfm.Android/Classes/Navigation/AndroidNavigationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public sealed class AndroidNavigationManager : MobileNavigationManager
private Action<IBaseView> _onPlayerViewReady;
private Action<IBaseView> _onPreferencesViewReady;
private Action<IBaseView> _onEqualizerPresetsViewReady;
private Action<IBaseView> _onSyncViewReady;

public MainActivity MainActivity { get; set; }

Expand Down Expand Up @@ -98,6 +99,13 @@ protected override void CreateEqualizerPresetsViewInternal(Action<IBaseView> onV
MainActivity.StartActivity(intent);
}

protected override void CreateSyncViewInternal(Action<IBaseView> onViewReady)
{
_onSyncViewReady = onViewReady;
var intent = new Intent(MainActivity, typeof(SyncActivity));
MainActivity.StartActivity(intent);
}

public void SetPlayerActivityInstance(PlayerActivity activity)
{
if (_onPlayerViewReady != null)
Expand All @@ -115,5 +123,11 @@ public void SetEqualizerPresetsActivityInstance(EqualizerPresetsActivity activit
if (_onEqualizerPresetsViewReady != null)
_onEqualizerPresetsViewReady(activity);
}

public void SetSyncActivityInstance(SyncActivity activity)
{
if (_onSyncViewReady != null)
_onSyncViewReady(activity);
}
}
}
2 changes: 1 addition & 1 deletion MPfm/MPfm.Android/MPfm.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Classes\Activities\BaseActivity.cs" />
<Compile Include="Classes\Activities\SyncActivity.cs" />
<Compile Include="Classes\Activities\PlayerActivity.cs" />
<Compile Include="Classes\Activities\EqualizerPresetsActivity.cs" />
<Compile Include="Classes\Activities\MainActivity.cs" />
Expand All @@ -72,7 +73,6 @@
<Compile Include="Classes\Fragments\EqualizerPresetDetailsFragment.cs" />
<Compile Include="Classes\Fragments\SyncDownloadFragment.cs" />
<Compile Include="Classes\Fragments\SyncMenuFragment.cs" />
<Compile Include="Classes\Fragments\SyncFragment.cs" />
<Compile Include="Classes\Fragments\MainFragment.cs" />
<Compile Include="Classes\Fragments\PlayerMetadataFragment.cs" />
<Compile Include="Classes\Fragments\MarkersFragment.cs" />
Expand Down
Loading

0 comments on commit 6bb7ee7

Please sign in to comment.