Repository navigation
Expand file tree
/
Copy pathServiceBusyActivity.cs
More file actions
106 lines (91 loc) · 2.91 KB
/
Copy pathServiceBusyActivity.cs
File metadata and controls
106 lines (91 loc) · 2.91 KB
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
using System.Threading;
using Android.OS;
using Android.Views;
using Android.Views.InputMethods;
using Android.Widget;
using AndroidX.Annotations;
namespace BmwDeepObd;
[Android.App.Activity(Label = "@string/trans_api_key_title",
Name = ActivityCommon.AppNameSpace + "." + nameof(ServiceBusyActivity),
WindowSoftInputMode = SoftInput.StateAlwaysHidden,
ConfigurationChanges = ActivityConfigChanges)]
public class ServiceBusyActivity : BaseActivity
{
private Timer _statusCheckTimer;
private TextView _statusCaptionText;
private TextView _statusInfoText;
private TextView _statusText;
private ProgressBar _progressBar;
private Button _abortButton;
private Button _closeButton;
protected override void OnCreate(Bundle savedInstanceState)
{
SetTheme();
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.service_busy);
SetResult(Android.App.Result.Canceled);
_statusCaptionText = FindViewById<TextView>(Resource.Id.statusCaptionText);
_statusInfoText = FindViewById<TextView>(Resource.Id.statusInfoText);
_statusText = FindViewById<TextView>(Resource.Id.statusText);
_progressBar = FindViewById<ProgressBar>(Resource.Id.progressBar);
_abortButton = FindViewById<Button>(Resource.Id.abortButton);
_abortButton.Click += (sender, e) =>
{
ForegroundService.AbortThread = true;
};
_closeButton = FindViewById<Button>(Resource.Id.closeButton);
_closeButton.Click += (sender, e) =>
{
SetResult(Android.App.Result.Canceled);
Finish();
};
UpdateDisplay();
}
protected override void OnResume()
{
base.OnResume();
UpdateDisplay();
if (_statusCheckTimer == null)
{
_statusCheckTimer = new Timer(state =>
{
RunOnUiThread(() =>
{
if (!ForegroundService.IsCommThreadRunning())
{
if (ActivityCommon.CommActive)
{
SetResult(Android.App.Result.Ok);
Finish();
return;
}
}
UpdateDisplay();
});
}, null, 1000, 1000);
}
}
protected override void OnPause()
{
base.OnPause();
DisposeTimer();
}
protected override void OnDestroy()
{
base.OnDestroy();
DisposeTimer();
}
private void UpdateDisplay()
{
_statusText.Text = ForegroundService.GetStatusText(this);
_abortButton.Enabled = !ForegroundService.AbortThread;
}
private void DisposeTimer()
{
if (_statusCheckTimer != null)
{
_statusCheckTimer.Dispose();
_statusCheckTimer = null;
}
}
}