-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMainActivity.cs
More file actions
82 lines (73 loc) · 3 KB
/
MainActivity.cs
File metadata and controls
82 lines (73 loc) · 3 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
using Android.Content;
using Android.OS;
using Android.Views;
using AndroidX.AppCompat.App;
using AndroidX.Core.View;
using AndroidX.LocalBroadcastManager.Content;
namespace CameraXBasic
{
// Main entry point into our app. This app follows the single-activity pattern, and all
// functionality is implemented in the form of fragments.
[Activity(Name = "com.android.example.cameraxbasic.MainActivity", Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
public const string KeyEventAction = "key_event_action";
public const string KeyEventExtra = "key_event_extra";
private const long ImmersiveFlagTimeout = 500L;
private FrameLayout container;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
container = FindViewById(Resource.Id.fragment_container) as FrameLayout;
}
protected override void OnResume()
{
base.OnResume();
// Before setting full screen flags, we must wait a bit to let UI settle; otherwise, we may
// be trying to set app to immersive mode before it's ready and the flags do not stick
container.PostDelayed(() => HideSystemUI(),
ImmersiveFlagTimeout);
}
// When key down event is triggered, relay it via local broadcast so fragments can handle it
public override bool OnKeyDown(Keycode keyCode, KeyEvent msg)
{
if (keyCode == Keycode.VolumeDown)
{
var intent = new Intent(KeyEventAction);
intent.PutExtra(KeyEventExtra, (int) keyCode);
#pragma warning disable 0618
LocalBroadcastManager.GetInstance(this).SendBroadcast(intent);
#pragma warning restore 0618
return true;
}
else
{
return base.OnKeyDown(keyCode, msg);
}
}
public override void OnBackPressed()
{
if (Build.VERSION.SdkInt == BuildVersionCodes.P)
{
// Workaround for Android Q memory leak issue in IRequestFinishCallback$Stub.
// (https://issuetracker.google.com/issues/139738913)
FinishAfterTransition();
}
else
{
#pragma warning disable CA1422
base.OnBackPressed();
#pragma warning restore CA1422
}
}
private void HideSystemUI()
{
WindowCompat.SetDecorFitsSystemWindows(Window, false);
WindowInsetsControllerCompat controller = new WindowInsetsControllerCompat(Window, container);
controller.Hide(WindowInsetsCompat.Type.SystemBars());
controller.SystemBarsBehavior = WindowInsetsControllerCompat.BehaviorShowTransientBarsBySwipe;
}
}
}