Skip to content

Commit

Permalink
Android: Fixed layout bugs on Equalizer Preset screens. Implemented d…
Browse files Browse the repository at this point in the history
…rawing for Equalizer Preset Graph View. Fixed several bugs in Equalizer Preset logic. Added selector for buttons. Added prototype for Wi-fi Direct and Network Device Discovery for Android 4.1+.

Related to issue #406.
  • Loading branch information
ycastonguay-cbc committed Aug 1, 2013
1 parent e2768f4 commit 314c474
Show file tree
Hide file tree
Showing 23 changed files with 796 additions and 121 deletions.
Expand Up @@ -21,18 +21,20 @@
using Android.Content.PM;
using Android.Views;
using Android.OS;
using Android.Views.InputMethods;
using Android.Widget;
using MPfm.Android.Classes.Adapters;
using MPfm.Android.Classes.Navigation;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Navigation;
using MPfm.MVP.Views;
using MPfm.Player.Objects;
using org.sessionsapp.android;

namespace MPfm.Android
{
[Activity(Label = "Equalizer Preset Details", ScreenOrientation = ScreenOrientation.Sensor, Theme = "@style/MyAppTheme", ConfigurationChanges = ConfigChanges.KeyboardHidden | ConfigChanges.Orientation | ConfigChanges.ScreenSize, WindowSoftInputMode = SoftInput.StateHidden)]
public class EqualizerPresetDetailsActivity : BaseActivity, IEqualizerPresetDetailsView
public class EqualizerPresetDetailsActivity : BaseActivity, IEqualizerPresetDetailsView, EditText.IOnEditorActionListener
{
private MobileNavigationManager _navigationManager;
private string _sourceActivityType;
Expand All @@ -42,6 +44,7 @@ public class EqualizerPresetDetailsActivity : BaseActivity, IEqualizerPresetDeta
private Button _btnNormalize;
private Button _btnReset;
private EQPreset _preset;
private EqualizerPresetGraphView _equalizerPresetGraph;

protected override void OnCreate(Bundle bundle)
{
Expand All @@ -56,11 +59,14 @@ protected override void OnCreate(Bundle bundle)
_txtPresetName = FindViewById<EditText>(Resource.Id.equalizerPresetDetails_txtPresetName);
_btnNormalize = FindViewById<Button>(Resource.Id.equalizerPresetDetails_btnNormalize);
_btnReset = FindViewById<Button>(Resource.Id.equalizerPresetDetails_btnReset);
_btnNormalize.Click += (sender, args) => OnNormalizePreset();
_btnReset.Click += (sender, args) => OnResetPreset();
_equalizerPresetGraph = FindViewById<EqualizerPresetGraphView>(Resource.Id.equalizerPresetDetails_graphView);
_btnNormalize.Click += BtnNormalizeOnClick;
_btnReset.Click += BtnResetOnClick;

//_txtPresetName.SetOnEditorActionListener(this);

_listView = FindViewById<ListView>(Resource.Id.equalizerPresetDetails_listView);
_listAdapter = new EqualizerPresetFadersListAdapter(this, new EQPreset());
_listAdapter = new EqualizerPresetFadersListAdapter(this, _listView, new EQPreset());
_listView.SetAdapter(_listAdapter);

// Save the source activity type for later (for providing Up navigation)
Expand Down Expand Up @@ -106,6 +112,32 @@ protected override void OnDestroy()
base.OnDestroy();
}

private void BtnResetOnClick(object sender, EventArgs eventArgs)
{
AlertDialog ad = new AlertDialog.Builder(this)
.SetIconAttribute(global::Android.Resource.Attribute.AlertDialogIcon)
.SetTitle("Equalizer preset will be reset")
.SetMessage("Are you sure you wish to reset this equalizer preset?")
.SetCancelable(true)
.SetPositiveButton("OK", (sender2, args) => OnResetPreset())
.SetNegativeButton("Cancel", (sender2, args) => { })
.Create();
ad.Show();
}

private void BtnNormalizeOnClick(object sender, EventArgs eventArgs)
{
AlertDialog ad = new AlertDialog.Builder(this)
.SetIconAttribute(global::Android.Resource.Attribute.AlertDialogIcon)
.SetTitle("Equalizer preset will be normalized")
.SetMessage("Are you sure you wish to normalize this equalizer preset?")
.SetCancelable(true)
.SetPositiveButton("OK", (sender2, args) => OnNormalizePreset())
.SetNegativeButton("Cancel", (sender2, args) => { })
.Create();
ad.Show();
}

public override bool OnCreateOptionsMenu(IMenu menu)
{
MenuInflater.Inflate(Resource.Menu.equalizerpresetdetails_menu, menu);
Expand Down Expand Up @@ -169,6 +201,28 @@ private void ConfirmExitActivity()
ad.Show();
}

public void UpdatePreset(EQPreset preset)
{
//Console.WriteLine("EQDA - UPDATE PRESET");
_preset = preset;
_equalizerPresetGraph.SetPreset(preset);
_txtPresetName.Text = preset.Name;
}

public bool OnEditorAction(TextView v, ImeAction actionId, KeyEvent e)
{
//if (e.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter)
if(actionId == ImeAction.Done)
{
//var imm = (InputMethodManager)ApplicationContext.GetSystemService(Context.InputMethodService);
//imm.HideSoftInputFromInputMethod(v.WindowToken, 0);
Window.SetSoftInputMode(SoftInput.StateAlwaysHidden);
return true;
}

return false;
}

#region IEqualizerPresetDetailsView implementation

public Action OnResetPreset { get; set; }
Expand Down Expand Up @@ -202,13 +256,14 @@ public void ShowMessage(string title, string message)

public void RefreshPreset(EQPreset preset)
{
//Console.WriteLine("EQDA - REFRESH PRESET");
RunOnUiThread(() => {
_preset = preset;
_txtPresetName.Text = preset.Name;
UpdatePreset(preset);
_listAdapter.SetData(preset);
});
}

#endregion

}
}
120 changes: 79 additions & 41 deletions MPfm/MPfm.Android/Classes/Activities/MainActivity.cs
Expand Up @@ -23,7 +23,7 @@
using Android.Content;
using Android.Content.PM;
using Android.Graphics;
using Android.Net.Nsd;
using Android.Net.Wifi.P2p;
using Android.Support.V4.App;
using Android.Support.V4.View;
using Android.Views;
Expand All @@ -34,7 +34,10 @@
using MPfm.Android.Classes.Adapters;
using MPfm.Android.Classes.Cache;
using MPfm.Android.Classes.Fragments;
using MPfm.Android.Classes.Listeners;
using MPfm.Android.Classes.Navigation;
using MPfm.Android.Classes.Receivers;
using MPfm.Android.Classes.Services;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Messages;
using MPfm.MVP.Navigation;
Expand Down Expand Up @@ -66,6 +69,15 @@ public class MainActivity : BaseActivity, IMobileOptionsMenuView, View.IOnTouchL
private ImageButton _btnPlayPause;
private ImageButton _btnNext;
private bool _isPlaying;
private IntentFilter _intentFilter;
private WifiP2pManager _wifiManager;
private WifiP2pManager.Channel _wifiChannel;
private WifiDirectReceiver _wifiDirectReceiver;
private ActionListener _actionListener;

//#if __ANDROID_16__
//private AndroidDiscoveryService _discoveryService;
//#endif

public BitmapCache BitmapCache { get; private set; }

Expand Down Expand Up @@ -176,14 +188,14 @@ protected override void OnCreate(Bundle bundle)
});
});

SetupNotificationBar();
//#if __ANDROID_16__
// if (((int)global::Android.OS.Build.VERSION.SdkInt) >= 16) {
// _discoveryService = new AndroidDiscoveryService();
// _discoveryService.StartDiscovery();
// }
//#endif

#if __ANDROID_16__
if (((int)global::Android.OS.Build.VERSION.SdkInt) >= 16) {
Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! USING SOMETHING FROM API 16 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
NsdServiceInfo serviceInfo = new NsdServiceInfo();
}
#endif
SetupNotificationBar();

Console.WriteLine("MainActivity - OnCreate - Starting navigation manager...");
_navigationManager = (AndroidNavigationManager) Bootstrapper.GetContainer().Resolve<MobileNavigationManager>();
Expand All @@ -192,6 +204,23 @@ protected override void OnCreate(Bundle bundle)
_navigationManager.Start();
}

//private void SetupWifiDirect()
//{
// _intentFilter = new IntentFilter();
// _intentFilter.AddAction(WifiP2pManager.WifiP2pStateChangedAction);
// _intentFilter.AddAction(WifiP2pManager.WifiP2pPeersChangedAction);
// _intentFilter.AddAction(WifiP2pManager.WifiP2pConnectionChangedAction);
// _intentFilter.AddAction(WifiP2pManager.WifiP2pThisDeviceChangedAction);

// _actionListener = new ActionListener();
// _wifiManager = (WifiP2pManager) GetSystemService(Context.WifiP2pService);
// _wifiChannel = _wifiManager.Initialize(this, MainLooper, null);
// _wifiDirectReceiver = new WifiDirectReceiver();
// RegisterReceiver(_wifiDirectReceiver, _intentFilter);

// _wifiManager.DiscoverPeers(_wifiChannel, _actionListener);
//}

private void SetupNotificationBar()
{
// Build permanent notification for displaying player status in notification drawer (not sure yet how to make the notification sticky or to use the big style with custom layout)
Expand Down Expand Up @@ -306,42 +335,51 @@ public override void OnBackPressed()
}
}

public override bool OnPrepareOptionsMenu(IMenu menu)
{
Console.WriteLine("MainActivity - OnPrepareOptionsMenu");
return true;
}

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

MenuInflater.Inflate(Resource.Menu.main_menu, menu);
//Console.WriteLine("MainActivity - OnCreateOptionsMenu");

foreach (var option in _options)
{
var menuItem = menu.Add(new Java.Lang.String(option.Value));
switch (option.Key)
{
case MobileOptionsMenuType.About:
menuItem.SetIcon(Resource.Drawable.actionbar_info);
break;
case MobileOptionsMenuType.EqualizerPresets:
menuItem.SetShowAsAction(ShowAsAction.IfRoom);
menuItem.SetIcon(Resource.Drawable.actionbar_equalizer);
break;
case MobileOptionsMenuType.Preferences:
menuItem.SetShowAsAction(ShowAsAction.IfRoom);
menuItem.SetIcon(Resource.Drawable.actionbar_settings);
break;
case MobileOptionsMenuType.SyncLibrary:
menuItem.SetShowAsAction(ShowAsAction.IfRoom);
menuItem.SetIcon(Resource.Drawable.actionbar_sync);
break;
case MobileOptionsMenuType.SyncLibraryCloud:
menuItem.SetIcon(Resource.Drawable.actionbar_cloud);
break;
case MobileOptionsMenuType.SyncLibraryFileSharing:
menuItem.SetIcon(Resource.Drawable.actionbar_share);
break;
case MobileOptionsMenuType.SyncLibraryWebBrowser:
menuItem.SetIcon(Resource.Drawable.actionbar_earth);
break;
}
}
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"));
//foreach (var option in _options)
//{
// var menuItem = menu.Add(new Java.Lang.String(option.Value));
// switch (option.Key)
// {
// case MobileOptionsMenuType.About:
// menuItem.SetIcon(Resource.Drawable.actionbar_info);
// break;
// case MobileOptionsMenuType.EqualizerPresets:
// menuItem.SetShowAsAction(ShowAsAction.IfRoom);
// menuItem.SetIcon(Resource.Drawable.actionbar_equalizer);
// break;
// case MobileOptionsMenuType.Preferences:
// menuItem.SetShowAsAction(ShowAsAction.IfRoom);
// menuItem.SetIcon(Resource.Drawable.actionbar_settings);
// break;
// case MobileOptionsMenuType.SyncLibrary:
// menuItem.SetShowAsAction(ShowAsAction.IfRoom);
// menuItem.SetIcon(Resource.Drawable.actionbar_sync);
// break;
// case MobileOptionsMenuType.SyncLibraryCloud:
// menuItem.SetIcon(Resource.Drawable.actionbar_cloud);
// break;
// case MobileOptionsMenuType.SyncLibraryFileSharing:
// menuItem.SetIcon(Resource.Drawable.actionbar_share);
// break;
// case MobileOptionsMenuType.SyncLibraryWebBrowser:
// menuItem.SetIcon(Resource.Drawable.actionbar_earth);
// break;
// }
//}

return true;
}
Expand Down
Expand Up @@ -27,16 +27,18 @@

namespace MPfm.Android.Classes.Adapters
{
public class EqualizerPresetFadersListAdapter : BaseAdapter<EQPresetBand>
public class EqualizerPresetFadersListAdapter : BaseAdapter<EQPresetBand>, SeekBar.IOnSeekBarChangeListener
{
private readonly EqualizerPresetDetailsActivity _context;
private readonly ListView _listView;
private EQPreset _preset;

public bool HasPresetChanged { get; set; }

public EqualizerPresetFadersListAdapter(EqualizerPresetDetailsActivity context, EQPreset preset)
public EqualizerPresetFadersListAdapter(EqualizerPresetDetailsActivity context, ListView listView, EQPreset preset)
{
_context = context;
_listView = listView;
_preset = preset;
}

Expand Down Expand Up @@ -76,13 +78,8 @@ public override View GetView(int position, View convertView, ViewGroup parent)
lblFrequency.Text = _preset.Bands[position].CenterString;
lblValue.Text = GetGainString(_preset.Bands[position].Gain);
seekBar.Progress = progress;
seekBar.ProgressChanged += (sender, args) => {
HasPresetChanged = true;
float gain = (((float)seekBar.Progress) / 10f) - 6f;
lblValue.Text = GetGainString(gain);
_preset.Bands[position].Gain = gain;
_context.OnSetFaderGain(_preset.Bands[position].CenterString, gain);
};
seekBar.Tag = position;
seekBar.SetOnSeekBarChangeListener(this);

return view;
}
Expand All @@ -94,5 +91,32 @@ private string GetGainString(float gain)
else
return gain.ToString("0.0").Replace(",", ".") + " dB";
}

public void OnProgressChanged(SeekBar seekBar, int progress, bool fromUser)
{
int position = (int)seekBar.Tag;
//Console.WriteLine("EPFLA - ONPROGRESSCHANGED position: {0} progress: {1}", position, progress);
HasPresetChanged = true;
float gain = (((float)seekBar.Progress) / 10f) - 6f;

var view = _listView.GetChildAt(position - _listView.FirstVisiblePosition);
if (view == null)
return;

var lblValue = view.FindViewById<TextView>(Resource.Id.equalizerPresetFaderCell_lblValue);
lblValue.Text = GetGainString(gain);

_preset.Bands[position].Gain = gain;
_context.UpdatePreset(_preset);
_context.OnSetFaderGain(_preset.Bands[position].CenterString, gain);
}

public void OnStartTrackingTouch(SeekBar seekBar)
{
}

public void OnStopTrackingTouch(SeekBar seekBar)
{
}
}
}

0 comments on commit 314c474

Please sign in to comment.