@@ -3,111 +3,120 @@ package com.programminghoch10.RotationControl
33import android.app.Application
44import android.content.pm.ActivityInfo
55
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+ }
716
817enum class ROTATION_MODE (val key : String , val value : Int , val title : String , val summary : String ) {
918 // yoinked from https://developer.android.com/reference/android/R.attr.html#screenOrientation
1019
1120 SCREEN_ORIENTATION_UNSET (
1221 " UNSET" ,
1322 - 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),
1625 ),
1726 SCREEN_ORIENTATION_UNSPECIFIED (
1827 " UNSPECIFIED" ,
1928 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),
2231 ),
2332 SCREEN_ORIENTATION_LANDSCAPE (
2433 " LANDSCAPE" ,
2534 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),
2837 ),
2938 SCREEN_ORIENTATION_PORTRAIT (
3039 " PORTRAIT" ,
3140 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),
3443 ),
3544 SCREEN_ORIENTATION_USER (
3645 " USER" ,
3746 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),
4049 ),
4150 SCREEN_ORIENTATION_BEHIND (
4251 " BEHIND" ,
4352 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),
4655 ),
4756 SCREEN_ORIENTATION_SENSOR (
4857 " SENSOR" ,
4958 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),
5261 ),
5362 SCREEN_ORIENTATION_NOSENSOR (
5463 " NOSENSOR" ,
5564 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),
5867 ),
5968 SCREEN_ORIENTATION_SENSOR_LANDSCAPE (
6069 " SENSOR_LANDSCAPE" ,
6170 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),
6473 ),
6574 SCREEN_ORIENTATION_SENSOR_PORTRAIT (
6675 " SENSOR_PORTRAIT" ,
6776 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),
7079 ),
7180 SCREEN_ORIENTATION_REVERSE_LANDSCAPE (
7281 " REVERSE_LANDSCAPE" ,
7382 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),
7685 ),
7786 SCREEN_ORIENTATION_REVERSE_PORTRAIT (
7887 " REVERSE_PORTRAIT" ,
7988 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),
8291 ),
8392 SCREEN_ORIENTATION_FULL_SENSOR (
8493 " FULL_SENSOR" ,
8594 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),
8897 ),
8998 SCREEN_ORIENTATION_USER_LANDSCAPE (
9099 " USER_LANDSCAPE" ,
91100 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),
94103 ),
95104 SCREEN_ORIENTATION_USER_PORTRAIT (
96105 " USER_PORTRAIT" ,
97106 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),
100109 ),
101110 SCREEN_ORIENTATION_FULL_USER (
102111 " FULL_USER" ,
103112 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),
106115 ),
107116 SCREEN_ORIENTATION_LOCKED (
108117 " LOCKED" ,
109118 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),
112121 ),
113122}
0 commit comments