@@ -3,111 +3,120 @@ package com.programminghoch10.RotationControl
3
3
import android.app.Application
4
4
import android.content.pm.ActivityInfo
5
5
6
- val context = Class .forName(" android.app.ActivityThread" ).getMethod(" currentApplication" ).invoke(null ) as Application
6
+ val context = run {
7
+ val applicationContext = Class .forName(" android.app.ActivityThread" ).getMethod(" currentApplication" ).invoke(null ) as Application ?
8
+ if (applicationContext?.packageName == BuildConfig .APPLICATION_ID ) return @run applicationContext.resources
9
+ return @run null
10
+ }
11
+
12
+ private fun getString (id : Int ): String {
13
+ if (context == null ) return " "
14
+ return context.getString(id)
15
+ }
7
16
8
17
enum class ROTATION_MODE (val key : String , val value : Int , val title : String , val summary : String ) {
9
18
// yoinked from https://developer.android.com/reference/android/R.attr.html#screenOrientation
10
19
11
20
SCREEN_ORIENTATION_UNSET (
12
21
" UNSET" ,
13
22
- 2 ,
14
- context. getString(R .string.screen_orientation_unset_title),
15
- context. getString(R .string.screen_orientation_unset_summary),
23
+ getString(R .string.screen_orientation_unset_title),
24
+ getString(R .string.screen_orientation_unset_summary),
16
25
),
17
26
SCREEN_ORIENTATION_UNSPECIFIED (
18
27
" UNSPECIFIED" ,
19
28
ActivityInfo .SCREEN_ORIENTATION_UNSPECIFIED ,
20
- context. getString(R .string.screen_orientation_unspecified_title),
21
- context. getString(R .string.screen_orientation_unspecified_summary),
29
+ getString(R .string.screen_orientation_unspecified_title),
30
+ getString(R .string.screen_orientation_unspecified_summary),
22
31
),
23
32
SCREEN_ORIENTATION_LANDSCAPE (
24
33
" LANDSCAPE" ,
25
34
ActivityInfo .SCREEN_ORIENTATION_LANDSCAPE ,
26
- context. getString(R .string.screen_orientation_landscape_title),
27
- context. getString(R .string.screen_orientation_landscape_summary),
35
+ getString(R .string.screen_orientation_landscape_title),
36
+ getString(R .string.screen_orientation_landscape_summary),
28
37
),
29
38
SCREEN_ORIENTATION_PORTRAIT (
30
39
" PORTRAIT" ,
31
40
ActivityInfo .SCREEN_ORIENTATION_PORTRAIT ,
32
- context. getString(R .string.screen_orientation_portrait_title),
33
- context. getString(R .string.screen_orientation_portrait_summary),
41
+ getString(R .string.screen_orientation_portrait_title),
42
+ getString(R .string.screen_orientation_portrait_summary),
34
43
),
35
44
SCREEN_ORIENTATION_USER (
36
45
" USER" ,
37
46
ActivityInfo .SCREEN_ORIENTATION_USER ,
38
- context. getString(R .string.screen_orientation_user_title),
39
- context. getString(R .string.screen_orientation_user_summary),
47
+ getString(R .string.screen_orientation_user_title),
48
+ getString(R .string.screen_orientation_user_summary),
40
49
),
41
50
SCREEN_ORIENTATION_BEHIND (
42
51
" BEHIND" ,
43
52
ActivityInfo .SCREEN_ORIENTATION_BEHIND ,
44
- context. getString(R .string.screen_orientation_behind_title),
45
- context. getString(R .string.screen_orientation_behind_summary),
53
+ getString(R .string.screen_orientation_behind_title),
54
+ getString(R .string.screen_orientation_behind_summary),
46
55
),
47
56
SCREEN_ORIENTATION_SENSOR (
48
57
" SENSOR" ,
49
58
ActivityInfo .SCREEN_ORIENTATION_SENSOR ,
50
- context. getString(R .string.screen_orientation_sensor_title),
51
- context. getString(R .string.screen_orientation_sensor_summary),
59
+ getString(R .string.screen_orientation_sensor_title),
60
+ getString(R .string.screen_orientation_sensor_summary),
52
61
),
53
62
SCREEN_ORIENTATION_NOSENSOR (
54
63
" NOSENSOR" ,
55
64
ActivityInfo .SCREEN_ORIENTATION_NOSENSOR ,
56
- context. getString(R .string.screen_orientation_nosensor_title),
57
- context. getString(R .string.screen_orientation_nosensor_summary),
65
+ getString(R .string.screen_orientation_nosensor_title),
66
+ getString(R .string.screen_orientation_nosensor_summary),
58
67
),
59
68
SCREEN_ORIENTATION_SENSOR_LANDSCAPE (
60
69
" SENSOR_LANDSCAPE" ,
61
70
ActivityInfo .SCREEN_ORIENTATION_SENSOR_LANDSCAPE ,
62
- context. getString(R .string.screen_orientation_sensor_landscape_title),
63
- context. getString(R .string.screen_orientation_sensor_landscape_summary),
71
+ getString(R .string.screen_orientation_sensor_landscape_title),
72
+ getString(R .string.screen_orientation_sensor_landscape_summary),
64
73
),
65
74
SCREEN_ORIENTATION_SENSOR_PORTRAIT (
66
75
" SENSOR_PORTRAIT" ,
67
76
ActivityInfo .SCREEN_ORIENTATION_SENSOR_PORTRAIT ,
68
- context. getString(R .string.screen_orientation_sensor_portrait_title),
69
- context. getString(R .string.screen_orientation_sensor_portrait_summary),
77
+ getString(R .string.screen_orientation_sensor_portrait_title),
78
+ getString(R .string.screen_orientation_sensor_portrait_summary),
70
79
),
71
80
SCREEN_ORIENTATION_REVERSE_LANDSCAPE (
72
81
" REVERSE_LANDSCAPE" ,
73
82
ActivityInfo .SCREEN_ORIENTATION_REVERSE_LANDSCAPE ,
74
- context. getString(R .string.screen_orientation_reverse_landscape_title),
75
- context. getString(R .string.screen_orientation_reverse_landscape_summary),
83
+ getString(R .string.screen_orientation_reverse_landscape_title),
84
+ getString(R .string.screen_orientation_reverse_landscape_summary),
76
85
),
77
86
SCREEN_ORIENTATION_REVERSE_PORTRAIT (
78
87
" REVERSE_PORTRAIT" ,
79
88
ActivityInfo .SCREEN_ORIENTATION_REVERSE_PORTRAIT ,
80
- context. getString(R .string.screen_orientation_reverse_portrait_title),
81
- context. getString(R .string.screen_orientation_reverse_portrait_summary),
89
+ getString(R .string.screen_orientation_reverse_portrait_title),
90
+ getString(R .string.screen_orientation_reverse_portrait_summary),
82
91
),
83
92
SCREEN_ORIENTATION_FULL_SENSOR (
84
93
" FULL_SENSOR" ,
85
94
ActivityInfo .SCREEN_ORIENTATION_FULL_SENSOR ,
86
- context. getString(R .string.screen_orientation_full_sensor_title),
87
- context. getString(R .string.screen_orientation_full_sensor_summary),
95
+ getString(R .string.screen_orientation_full_sensor_title),
96
+ getString(R .string.screen_orientation_full_sensor_summary),
88
97
),
89
98
SCREEN_ORIENTATION_USER_LANDSCAPE (
90
99
" USER_LANDSCAPE" ,
91
100
ActivityInfo .SCREEN_ORIENTATION_USER_LANDSCAPE ,
92
- context. getString(R .string.screen_orientation_user_landscape),
93
- context. getString(R .string.screen_orientation_user_landscape_summary),
101
+ getString(R .string.screen_orientation_user_landscape),
102
+ getString(R .string.screen_orientation_user_landscape_summary),
94
103
),
95
104
SCREEN_ORIENTATION_USER_PORTRAIT (
96
105
" USER_PORTRAIT" ,
97
106
ActivityInfo .SCREEN_ORIENTATION_USER_PORTRAIT ,
98
- context. getString(R .string.screen_orientation_user_portrait_title),
99
- context. getString(R .string.screen_orientation_user_portrait_summary),
107
+ getString(R .string.screen_orientation_user_portrait_title),
108
+ getString(R .string.screen_orientation_user_portrait_summary),
100
109
),
101
110
SCREEN_ORIENTATION_FULL_USER (
102
111
" FULL_USER" ,
103
112
ActivityInfo .SCREEN_ORIENTATION_FULL_USER ,
104
- context. getString(R .string.screen_orientation_full_user_title),
105
- context. getString(R .string.screen_orientation_full_user_summary),
113
+ getString(R .string.screen_orientation_full_user_title),
114
+ getString(R .string.screen_orientation_full_user_summary),
106
115
),
107
116
SCREEN_ORIENTATION_LOCKED (
108
117
" LOCKED" ,
109
118
ActivityInfo .SCREEN_ORIENTATION_LOCKED ,
110
- context. getString(R .string.screen_orientation_locked_title),
111
- context. getString(R .string.screen_orientation_locked_summary),
119
+ getString(R .string.screen_orientation_locked_title),
120
+ getString(R .string.screen_orientation_locked_summary),
112
121
),
113
122
}
0 commit comments