Skip to content

Commit

Permalink
Android: Added UI for EqualizerPresetDetails with all hooks to presen…
Browse files Browse the repository at this point in the history
…ter.

Related to issue #406.
  • Loading branch information
ycastonguay committed Jul 10, 2013
1 parent ea8ef3e commit e8d377a
Show file tree
Hide file tree
Showing 11 changed files with 529 additions and 259 deletions.
Expand Up @@ -24,19 +24,28 @@
using Android.Support.V4.App;
using Android.Views;
using Android.OS;
using Android.Widget;
using MPfm.Android.Classes.Adapters;
using MPfm.Android.Classes.Navigation;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Navigation;
using MPfm.MVP.Presenters;
using MPfm.MVP.Views;
using MPfm.Player.Objects;

namespace MPfm.Android
{
[Activity(Label = "Equalizer Preset Details", ScreenOrientation = ScreenOrientation.Sensor, Theme = "@style/MyAppTheme", ConfigurationChanges = ConfigChanges.KeyboardHidden | ConfigChanges.Orientation | ConfigChanges.ScreenSize)]
[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
{
private MobileNavigationManager _navigationManager;
private string _sourceActivityType;
private EqualizerPresetFadersListAdapter _listAdapter;
private ListView _listView;
private EditText _txtPresetName;
private Button _btnNormalize;
private Button _btnReset;
private EQPreset _preset;

protected override void OnCreate(Bundle bundle)
{
Expand All @@ -48,6 +57,16 @@ protected override void OnCreate(Bundle bundle)
ActionBar.SetDisplayHomeAsUpEnabled(true);
ActionBar.SetHomeButtonEnabled(true);

_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();

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

// Save the source activity type for later (for providing Up navigation)
_sourceActivityType = Intent.GetStringExtra("sourceActivity");

Expand Down Expand Up @@ -91,24 +110,69 @@ protected override void OnDestroy()
base.OnDestroy();
}

public override bool OnCreateOptionsMenu(IMenu menu)
{
MenuInflater.Inflate(Resource.Menu.equalizerpresetdetails_menu, menu);
Console.WriteLine("EqualizerPresetDetailsActivity - OnCreateOptionsMenu");
return true;
}

public override bool OnOptionsItemSelected(IMenuItem item)
{
switch (item.ItemId)
{
case global::Android.Resource.Id.Home:
if (_listAdapter.HasPresetChanged)
{
ConfirmExitActivity();
return true;
}

var type = Type.GetType(_sourceActivityType);
var intent = new Intent(this, type);
intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
this.StartActivity(intent);
this.Finish();
return true;
break;
case Resource.Id.equalizerPresetDetailsMenu_item_save:
Console.WriteLine("EqualizerPresetDetailsActivity - Menu item click - Saving preset...");
OnSavePreset(_txtPresetName.Text);
return true;
break;
default:
return base.OnOptionsItemSelected(item);
break;
}
}

public override void OnBackPressed()
{
if (_listAdapter.HasPresetChanged)
{
ConfirmExitActivity();
return;
}

base.OnBackPressed();
}

private void ConfirmExitActivity()
{
AlertDialog ad = new AlertDialog.Builder(this)
.SetIconAttribute(global::Android.Resource.Attribute.AlertDialogIcon)
.SetTitle("Equalizer preset has been modified")
.SetMessage("Are you sure you wish to exit this screen without saving?")
.SetCancelable(true)
.SetPositiveButton("OK", (sender, args) => {
OnRevertPreset();
Finish();
})
.SetNegativeButton("Cancel", (sender, args) => {})
.Create();
ad.Show();
}

#region IEqualizerPresetDetailsView implementation

public Action OnResetPreset { get; set; }
Expand All @@ -130,10 +194,23 @@ public void EqualizerPresetDetailsError(Exception ex)

public void ShowMessage(string title, string message)
{
RunOnUiThread(() => {
AlertDialog ad = new AlertDialog.Builder(this).Create();
ad.SetCancelable(false);
ad.SetTitle(title);
ad.SetMessage(message);
ad.SetButton("OK", (sender, args) => ad.Dismiss());
ad.Show();
});
}

public void RefreshPreset(EQPreset preset)
{
RunOnUiThread(() => {
_preset = preset;
_txtPresetName.Text = preset.Name;
_listAdapter.SetData(preset);
});
}

#endregion
Expand Down
@@ -0,0 +1,97 @@
// 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 System.Linq;
using Android.App;
using Android.Graphics;
using Android.Views;
using Android.Widget;
using MPfm.Core;
using MPfm.Player.Objects;

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

public bool HasPresetChanged { get; private set; }

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

public void SetData(EQPreset preset)
{
NotifyDataSetChanged();
}

public override long GetItemId(int position)
{
return position;
}

public override EQPresetBand this[int position]
{
get { return _preset.Bands[position]; }
}

public override int Count
{
get { return _preset.Bands.Count; }
}

public override View GetView(int position, View convertView, ViewGroup parent)
{
var item = _preset.Bands[position];
View view = convertView;
if (view == null) // no view to re-use, create new
view = _context.LayoutInflater.Inflate(Resource.Layout.EqualizerPresetFaderCell, null);

var lblFrequency = view.FindViewById<TextView>(Resource.Id.equalizerPresetFaderCell_lblFrequency);
var lblValue = view.FindViewById<TextView>(Resource.Id.equalizerPresetFaderCell_lblValue);
var seekBar = view.FindViewById<SeekBar>(Resource.Id.equalizerPresetFaderCell_seekBar);

int progress = (int) ((_preset.Bands[position].Gain + 6f)*10f);
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);
};

return view;
}

private string GetGainString(float gain)
{
if (gain > 0)
return "+" + gain.ToString("0.0").Replace(",", ".") + " dB";
else
return gain.ToString("0.0").Replace(",", ".") + " dB";
}
}
}
5 changes: 5 additions & 0 deletions MPfm/MPfm.Android/MPfm.Android.csproj
Expand Up @@ -63,6 +63,7 @@
<Compile Include="Classes\Activities\EqualizerPresetsActivity.cs" />
<Compile Include="Classes\Activities\MainActivity.cs" />
<Compile Include="Classes\Activities\PreferencesActivity.cs" />
<Compile Include="Classes\Adapters\EqualizerPresetFadersListAdapter.cs" />
<Compile Include="Classes\Adapters\MarkersListAdapter.cs" />
<Compile Include="Classes\Adapters\PreferencesFragmentPagerAdapter.cs" />
<Compile Include="Classes\Adapters\MainTabStatePagerAdapter.cs" />
Expand Down Expand Up @@ -175,6 +176,9 @@
<AndroidResource Include="Resources\Layout\MarkerDetails.axml">
<SubType>Designer</SubType>
</AndroidResource>
<AndroidResource Include="Resources\Layout\EqualizerPresetFaderCell.axml">
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\Values\Strings.xml" />
Expand Down Expand Up @@ -254,6 +258,7 @@
<AndroidResource Include="Resources\xml\widget_player.xml" />
<AndroidResource Include="Resources\Menu\player_menu.xml" />
<AndroidResource Include="Resources\Menu\equalizerpresets_menu.xml" />
<AndroidResource Include="Resources\Menu\equalizerpresetdetails_menu.xml" />
</ItemGroup>
<ItemGroup>
<Folder Include="Lib\armeabi\" />
Expand Down
53 changes: 37 additions & 16 deletions MPfm/MPfm.Android/Resources/Layout/EqualizerPresetDetails.axml
Expand Up @@ -3,7 +3,8 @@
android:id="@+id/equalizerPresetDetails_mainLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:layout_height="fill_parent"
android:background="@color/background">
<org.sessionsapp.android.EqualizerPresetGraphView
android:id="@+id/equalizerPresetDetails_graphView"
android:orientation="horizontal"
Expand All @@ -24,31 +25,51 @@
<TextView
android:id="@+id/equalizerPresetDetails_lblPresetName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="8dp"
android:text="Preset Name:"
android:textSize="14dp"
android:padding="8dp" />
android:textColor="#FFFFFF" />
<EditText
android:id="@+id/equalizerPresetDetails_txtPresetName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_weight="1"
android:paddingRight="8dp"
android:textSize="14dp"
android:textColor="#FFFFFF"
android:padding="8dp" />
</LinearLayout>
<ScrollView
android:id="@+id/equalizerPresetDetails_scrollView"
<ListView
android:id="@+id/equalizerPresetDetails_listView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<!-- Scroll view can only have one child -->
<LinearLayout
android:id="@+id/equalizerPresetDetails_scrollViewLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="8dp">
</LinearLayout>
</ScrollView>
android:layout_weight="1"
android:background="@android:color/transparent"
android:cacheColorHint="#333333"
android:divider="#FFFFFF"
android:listSelector="#CCCCCC" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="6dp">
<Button
android:id="@+id/equalizerPresetDetails_btnNormalize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Normalize"
android:textColor="#ffffffff"
android:textSize="14dp"
android:padding="8dp" />
<Button
android:id="@+id/equalizerPresetDetails_btnReset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reset"
android:textColor="#ffffffff"
android:textSize="14dp"
android:padding="8dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
33 changes: 33 additions & 0 deletions MPfm/MPfm.Android/Resources/Layout/EqualizerPresetFaderCell.axml
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="56dp"
android:padding="8dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/equalizerPresetFaderCell_lblFrequency"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:gravity="left"
android:text="55 Hz"
android:textColor="#FFFFFF"
android:textSize="14dp" />
<SeekBar
android:id="@+id/equalizerPresetFaderCell_seekBar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:gravity="center_vertical"
android:max="120" />
<TextView
android:id="@+id/equalizerPresetFaderCell_lblValue"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:gravity="right"
android:text="0.0dB"
android:textColor="#FFFFFF"
android:textSize="14dp" />
</LinearLayout>

0 comments on commit e8d377a

Please sign in to comment.