/
EqualizerPresetDetailsActivity.cs
269 lines (236 loc) · 10.2 KB
/
EqualizerPresetDetailsActivity.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// 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 Android.App;
using Android.Content;
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, EditText.IOnEditorActionListener
{
private MobileNavigationManager _navigationManager;
private string _sourceActivityType;
private EqualizerPresetFadersListAdapter _listAdapter;
private ListView _listView;
private EditText _txtPresetName;
private Button _btnNormalize;
private Button _btnReset;
private EQPreset _preset;
private EqualizerPresetGraphView _equalizerPresetGraph;
protected override void OnCreate(Bundle bundle)
{
Console.WriteLine("EqualizerPresetDetailsActivity - OnCreate");
base.OnCreate(bundle);
_navigationManager = Bootstrapper.GetContainer().Resolve<MobileNavigationManager>();
SetContentView(Resource.Layout.EqualizerPresetDetails);
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);
_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, _listView, new EQPreset());
_listView.SetAdapter(_listAdapter);
// Save the source activity type for later (for providing Up navigation)
_sourceActivityType = Intent.GetStringExtra("sourceActivity");
// Since the onViewReady action could not be added to an intent, tell the NavMgr the view is ready
((AndroidNavigationManager)_navigationManager).SetEqualizerPresetDetailsActivityInstance(this);
}
protected override void OnStart()
{
Console.WriteLine("EqualizerPresetDetailsActivity - OnStart");
base.OnStart();
}
protected override void OnRestart()
{
Console.WriteLine("EqualizerPresetDetailsActivity - OnRestart");
base.OnRestart();
}
protected override void OnPause()
{
Console.WriteLine("EqualizerPresetDetailsActivity - OnPause");
base.OnPause();
}
protected override void OnResume()
{
Console.WriteLine("EqualizerPresetDetailsActivity - OnResume");
base.OnResume();
}
protected override void OnStop()
{
Console.WriteLine("EqualizerPresetDetailsActivity - OnStop");
base.OnStop();
}
protected override void OnDestroy()
{
Console.WriteLine("EqualizerPresetDetailsActivity - 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);
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);
_listAdapter.HasPresetChanged = false;
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();
}
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; }
public Action OnNormalizePreset { get; set; }
public Action OnRevertPreset { get; set; }
public Action<string> OnSavePreset { get; set; }
public Action<string, float> OnSetFaderGain { get; set; }
public void EqualizerPresetDetailsError(Exception ex)
{
RunOnUiThread(() => {
AlertDialog ad = new AlertDialog.Builder(this).Create();
ad.SetCancelable(false);
ad.SetMessage(string.Format("An error has occured in EqualizerPresetDetails: {0}", ex));
ad.SetButton("OK", (sender, args) => ad.Dismiss());
ad.Show();
});
}
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)
{
//Console.WriteLine("EQDA - REFRESH PRESET");
RunOnUiThread(() => {
UpdatePreset(preset);
_listAdapter.SetData(preset);
});
}
#endregion
}
}