Skip to content

Commit c2464da

Browse files
extract ROTATION_MODE strings to resources
1 parent b52600f commit c2464da

File tree

2 files changed

+71
-63
lines changed

2 files changed

+71
-63
lines changed
Lines changed: 37 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,113 @@
11
package com.programminghoch10.RotationControl
22

3+
import android.app.Application
34
import android.content.pm.ActivityInfo
45

6+
val context = Class.forName("android.app.ActivityThread").getMethod("currentApplication").invoke(null) as Application
7+
58
enum class ROTATION_MODE(val key: String, val value: Int, val title: String, val summary: String) {
69
// yoinked from https://developer.android.com/reference/android/R.attr.html#screenOrientation
710

811
SCREEN_ORIENTATION_UNSET(
912
"UNSET",
1013
-2,
11-
"UNSET",
12-
"Do not override screen orientation. " +
13-
"You might as well disable the module instead of using this option.",
14+
context.getString(R.string.screen_orientation_unset_title),
15+
context.getString(R.string.screen_orientation_unset_summary),
1416
),
1517
SCREEN_ORIENTATION_UNSPECIFIED(
1618
"UNSPECIFIED",
1719
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED,
18-
"UNSPECIFIED",
19-
"No preference specified: " +
20-
"let the system decide the best orientation. " +
21-
"This will either be the orientation selected by the activity below, " +
22-
"or the user's preferred orientation if this activity is the bottom of a task. " +
23-
"If the user explicitly turned off sensor based orientation " +
24-
"through settings sensor based device rotation will be ignored. " +
25-
"If not by default sensor based orientation will be taken into account " +
26-
"and the orientation will changed based on how the user rotates the device.",
20+
context.getString(R.string.screen_orientation_unspecified_title),
21+
context.getString(R.string.screen_orientation_unspecified_summary),
2722
),
2823
SCREEN_ORIENTATION_LANDSCAPE(
2924
"LANDSCAPE",
3025
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
31-
"LANDSCAPE",
32-
"Would like to have the screen in a landscape orientation: " +
33-
"that is, with the display wider than it is tall, ignoring sensor data.",
26+
context.getString(R.string.screen_orientation_landscape_title),
27+
context.getString(R.string.screen_orientation_landscape_summary),
3428
),
3529
SCREEN_ORIENTATION_PORTRAIT(
3630
"PORTRAIT",
3731
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
38-
"PORTRAIT",
39-
"Would like to have the screen in a portrait orientation: " +
40-
"that is, with the display taller than it is wide, ignoring sensor data.",
32+
context.getString(R.string.screen_orientation_portrait_title),
33+
context.getString(R.string.screen_orientation_portrait_summary),
4134
),
4235
SCREEN_ORIENTATION_USER(
4336
"USER",
4437
ActivityInfo.SCREEN_ORIENTATION_USER,
45-
"USER",
46-
"Use the user's current preferred orientation of the handset.",
38+
context.getString(R.string.screen_orientation_user_title),
39+
context.getString(R.string.screen_orientation_user_summary),
4740
),
4841
SCREEN_ORIENTATION_BEHIND(
4942
"BEHIND",
5043
ActivityInfo.SCREEN_ORIENTATION_BEHIND,
51-
"BEHIND",
52-
"Keep the screen in the same orientation as whatever is behind this activity.",
44+
context.getString(R.string.screen_orientation_behind_title),
45+
context.getString(R.string.screen_orientation_behind_summary),
5346
),
5447
SCREEN_ORIENTATION_SENSOR(
5548
"SENSOR",
5649
ActivityInfo.SCREEN_ORIENTATION_SENSOR,
57-
"SENSOR",
58-
"Orientation is determined by a physical orientation sensor: " +
59-
"the display will rotate based on how the user moves the device. " +
60-
"Ignores user's setting to turn off sensor-based rotation.",
50+
context.getString(R.string.screen_orientation_sensor_title),
51+
context.getString(R.string.screen_orientation_sensor_summary),
6152
),
6253
SCREEN_ORIENTATION_NOSENSOR(
6354
"NOSENSOR",
6455
ActivityInfo.SCREEN_ORIENTATION_NOSENSOR,
65-
"NOSENSOR",
66-
"Always ignore orientation determined by orientation sensor: " +
67-
"the display will not rotate when the user moves the device.",
56+
context.getString(R.string.screen_orientation_nosensor_title),
57+
context.getString(R.string.screen_orientation_nosensor_summary),
6858
),
6959
SCREEN_ORIENTATION_SENSOR_LANDSCAPE(
7060
"SENSOR_LANDSCAPE",
7161
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
72-
"SENSOR_LANDSCAPE",
73-
"Would like to have the screen in landscape orientation, " +
74-
"but can use the sensor to change which direction the screen is facing. ",
62+
context.getString(R.string.screen_orientation_sensor_landscape_title),
63+
context.getString(R.string.screen_orientation_sensor_landscape_summary),
7564
),
7665
SCREEN_ORIENTATION_SENSOR_PORTRAIT(
7766
"SENSOR_PORTRAIT",
7867
ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT,
79-
"SENSOR_PORTRAIT",
80-
"Would like to have the screen in portrait orientation, " +
81-
"but can use the sensor to change which direction the screen is facing.",
68+
context.getString(R.string.screen_orientation_sensor_portrait_title),
69+
context.getString(R.string.screen_orientation_sensor_portrait_summary),
8270
),
8371
SCREEN_ORIENTATION_REVERSE_LANDSCAPE(
8472
"REVERSE_LANDSCAPE",
8573
ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE,
86-
"REVERSE_LANDSCAPE",
87-
"Would like to have the screen in landscape orientation, " +
88-
"turned in the opposite direction from normal landscape.",
74+
context.getString(R.string.screen_orientation_reverse_landscape_title),
75+
context.getString(R.string.screen_orientation_reverse_landscape_summary),
8976
),
9077
SCREEN_ORIENTATION_REVERSE_PORTRAIT(
9178
"REVERSE_PORTRAIT",
9279
ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
93-
"REVERSE_PORTRAIT",
94-
"Would like to have the screen in portrait orientation, " +
95-
"turned in the opposite direction from normal portrait.",
80+
context.getString(R.string.screen_orientation_reverse_portrait_title),
81+
context.getString(R.string.screen_orientation_reverse_portrait_summary),
9682
),
9783
SCREEN_ORIENTATION_FULL_SENSOR(
9884
"FULL_SENSOR",
9985
ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR,
100-
"FULL_SENSOR",
101-
"Orientation is determined by a physical orientation sensor: " +
102-
"the display will rotate based on how the user moves the device. " +
103-
"This allows any of the 4 possible rotations, " +
104-
"regardless of what the device will normally do " +
105-
"(for example some devices won't normally use 180 degree rotation).",
86+
context.getString(R.string.screen_orientation_full_sensor_title),
87+
context.getString(R.string.screen_orientation_full_sensor_summary),
10688
),
10789
SCREEN_ORIENTATION_USER_LANDSCAPE(
10890
"USER_LANDSCAPE",
10991
ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE,
110-
"USER_LANDSCAPE",
111-
"Would like to have the screen in landscape orientation, " +
112-
"but if the user has enabled sensor-based rotation " +
113-
"then we can use the sensor to change which direction the screen is facing.",
92+
context.getString(R.string.screen_orientation_user_landscape),
93+
context.getString(R.string.screen_orientation_user_landscape_summary),
11494
),
11595
SCREEN_ORIENTATION_USER_PORTRAIT(
11696
"USER_PORTRAIT",
11797
ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT,
118-
"USER_PORTRAIT",
119-
"Would like to have the screen in portrait orientation, " +
120-
"but if the user has enabled sensor-based rotation " +
121-
"then we can use the sensor to change which direction the screen is facing.",
98+
context.getString(R.string.screen_orientation_user_portrait_title),
99+
context.getString(R.string.screen_orientation_user_portrait_summary),
122100
),
123101
SCREEN_ORIENTATION_FULL_USER(
124102
"FULL_USER",
125103
ActivityInfo.SCREEN_ORIENTATION_FULL_USER,
126-
"FULL_USER",
127-
"Respect the user's sensor-based rotation preference, " +
128-
"but if sensor-based rotation is enabled " +
129-
"then allow the screen to rotate in all 4 possible directions " +
130-
"regardless of what the device will normally do " +
131-
"(for example some devices won't normally use 180 degree rotation).",
104+
context.getString(R.string.screen_orientation_full_user_title),
105+
context.getString(R.string.screen_orientation_full_user_summary),
132106
),
133107
SCREEN_ORIENTATION_LOCKED(
134108
"LOCKED",
135109
ActivityInfo.SCREEN_ORIENTATION_LOCKED,
136-
"LOCKED",
137-
"Screen is locked to its current rotation, whatever that is.",
110+
context.getString(R.string.screen_orientation_locked_title),
111+
context.getString(R.string.screen_orientation_locked_summary),
138112
),
139113
}

RotationControl/src/main/res/values/strings.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,38 @@
33
<string name="description">Force rotation for selected packages</string>
44
<string name="title_activity_settings">RotationControl Configuration</string>
55
<string name="category_rotation_mode">Rotation Mode</string>
6+
<string name="screen_orientation_unset_title">UNSET</string>
7+
<string name="screen_orientation_unset_summary">Do not override screen orientation. You might as well disable the module instead of using this option.</string>
8+
<string name="screen_orientation_unspecified_title">UNSPECIFIED</string>
9+
<string name="screen_orientation_unspecified_summary">No preference specified: let the system decide the best orientation. This will either be the orientation selected by the activity below, or the user\'s preferred orientation if this activity is the bottom of a task. If the user explicitly turned off sensor based orientation through settings sensor based device rotation will be ignored. If not by default sensor based orientation will be taken into account and the orientation will changed based on how the user rotates the device.</string>
10+
<string name="screen_orientation_landscape_title">LANDSCAPE</string>
11+
<string name="screen_orientation_landscape_summary">Would like to have the screen in a landscape orientation: that is, with the display wider than it is tall, ignoring sensor data.</string>
12+
<string name="screen_orientation_portrait_title">PORTRAIT</string>
13+
<string name="screen_orientation_portrait_summary">Would like to have the screen in a portrait orientation: that is, with the display taller than it is wide, ignoring sensor data.</string>
14+
<string name="screen_orientation_user_title">USER</string>
15+
<string name="screen_orientation_user_summary">Use the user\'s current preferred orientation of the handset.</string>
16+
<string name="screen_orientation_behind_title">BEHIND</string>
17+
<string name="screen_orientation_behind_summary">Keep the screen in the same orientation as whatever is behind this activity.</string>
18+
<string name="screen_orientation_sensor_title">SENSOR</string>
19+
<string name="screen_orientation_sensor_summary">Orientation is determined by a physical orientation sensor: the display will rotate based on how the user moves the device. Ignores user\'s setting to turn off sensor-based rotation.</string>
20+
<string name="screen_orientation_nosensor_title">NOSENSOR</string>
21+
<string name="screen_orientation_nosensor_summary">Always ignore orientation determined by orientation sensor: the display will not rotate when the user moves the device.</string>
22+
<string name="screen_orientation_sensor_landscape_title">SENSOR_LANDSCAPE</string>
23+
<string name="screen_orientation_sensor_landscape_summary">"Would like to have the screen in landscape orientation, but can use the sensor to change which direction the screen is facing. "</string>
24+
<string name="screen_orientation_sensor_portrait_title">SENSOR_PORTRAIT</string>
25+
<string name="screen_orientation_sensor_portrait_summary">Would like to have the screen in portrait orientation, but can use the sensor to change which direction the screen is facing.</string>
26+
<string name="screen_orientation_reverse_landscape_title">REVERSE_LANDSCAPE</string>
27+
<string name="screen_orientation_reverse_landscape_summary">Would like to have the screen in landscape orientation, turned in the opposite direction from normal landscape.</string>
28+
<string name="screen_orientation_reverse_portrait_title">REVERSE_PORTRAIT</string>
29+
<string name="screen_orientation_reverse_portrait_summary">Would like to have the screen in portrait orientation, turned in the opposite direction from normal portrait.</string>
30+
<string name="screen_orientation_full_sensor_title">FULL_SENSOR</string>
31+
<string name="screen_orientation_full_sensor_summary">Orientation is determined by a physical orientation sensor: the display will rotate based on how the user moves the device. This allows any of the 4 possible rotations, regardless of what the device will normally do (for example some devices won\'t normally use 180 degree rotation).</string>
32+
<string name="screen_orientation_user_landscape">USER_LANDSCAPE</string>
33+
<string name="screen_orientation_user_landscape_summary">Would like to have the screen in landscape orientation, but if the user has enabled sensor-based rotation then we can use the sensor to change which direction the screen is facing.</string>
34+
<string name="screen_orientation_user_portrait_title">USER_PORTRAIT</string>
35+
<string name="screen_orientation_user_portrait_summary">Would like to have the screen in portrait orientation, but if the user has enabled sensor-based rotation then we can use the sensor to change which direction the screen is facing.</string>
36+
<string name="screen_orientation_full_user_title">FULL_USER</string>
37+
<string name="screen_orientation_full_user_summary">Respect the user\'s sensor-based rotation preference, but if sensor-based rotation is enabled then allow the screen to rotate in all 4 possible directions regardless of what the device will normally do (for example some devices won\'t normally use 180 degree rotation).</string>
38+
<string name="screen_orientation_locked_title">LOCKED</string>
39+
<string name="screen_orientation_locked_summary">Screen is locked to its current rotation, whatever that is.</string>
640
</resources>

0 commit comments

Comments
 (0)