Skip to content

Commit

Permalink
[rotation]reverse landscape
Browse files Browse the repository at this point in the history
  • Loading branch information
ekibun committed Mar 12, 2019
1 parent ce80b66 commit 05f02e3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package soko.ekibun.tilesbox.service

import android.content.Intent
import android.graphics.drawable.Icon
import android.preference.PreferenceManager
import android.provider.Settings
import android.service.quicksettings.Tile
import android.service.quicksettings.TileService
Expand Down Expand Up @@ -39,7 +40,7 @@ class RotationQuickTileService : TileService() {

private fun toggleOrientation(): Int {
val oldOrientation = OrientationUtil.getCurrentOrientation(this)
val newOrientation = OrientationUtil.getOppositeOrientation(oldOrientation)
val newOrientation = OrientationUtil.getOppositeOrientation(oldOrientation, PreferenceManager.getDefaultSharedPreferences(this).getBoolean("rotation_reverse_landscape", false))

Settings.System.putInt(contentResolver, Settings.System.ACCELEROMETER_ROTATION, 0)
Settings.System.putInt(contentResolver, Settings.System.USER_ROTATION, newOrientation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ object OrientationUtil {
private const val ROTATION_LAND_REVERSE = Surface.ROTATION_270
const val ROTATION_AUTO = -1

fun getOppositeOrientation(orientation: Int): Int {
fun getOppositeOrientation(orientation: Int, reverse: Boolean): Int {
return when {
isPortrait(orientation) -> ROTATION_LAND
isPortrait(orientation) -> if(reverse) ROTATION_LAND_REVERSE else ROTATION_LAND
isLandscape(orientation) -> ROTATION_PORT
else -> ROTATION_AUTO
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<string name="rotation_portrait">纵向</string>
<string name="rotation_landscape">横向</string>
<string name="rotation_auto">自动旋转</string>
<string name="rotation_pref_reverse_landscape">横屏反转</string>

<!--round corner-->
<string name="pref_corner_cate">屏幕圆角</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<string name="rotation_portrait">Portrait</string>
<string name="rotation_landscape">Landscape</string>
<string name="rotation_auto">Rotation Auto</string>
<string name="rotation_pref_reverse_landscape">Reverse Landscape</string>

<!--round corner-->
<string name="pref_corner_cate">Rounded Corner</string>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
android:key="rotation_permit_float_window"
android:title="@string/permit_float_window" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_cate_other">
<SwitchPreference
android:key="rotation_reverse_landscape"
android:title="@string/rotation_pref_reverse_landscape" />
</PreferenceCategory>
</PreferenceScreen>
<PreferenceScreen
android:title="@string/pref_corner_cate"
Expand Down

0 comments on commit 05f02e3

Please sign in to comment.