Android编程Froyo2.2版本实现360度旋转

本文详细阐述了Android中WindowOrientationListener的实现机制,包括旋转角度阈值、表面旋转值映射以及当前旋转状态的更新逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

--- a/frameworks/base/core/java/android/view/WindowOrientationListener.java
+++ b/frameworks/base/core/java/android/view/WindowOrientationListener.java
@@ -124,13 +124,14 @@ public abstract class WindowOrientationListener {
private static final int ROTATION_0 = 0;
private static final int ROTATION_90 = 1;
private static final int ROTATION_270 = 2;
+ private static final int ROTATION_180 = 3;

// Current orientation state
private int mRotation = ROTATION_0;

// Mapping our internal aliases into actual Surface rotation values
private final int[] SURFACE_ROTATIONS = new int[] {
Surface.ROTATION_0,
Surface.ROTATION_90,
- Surface.ROTATION_270};
+ Surface.ROTATION_270,
Surface.ROTATION_180};

// Threshold ranges of orientation angle to transition into other orientation states.
// The first list is for transitions from ROTATION_0, the next for ROTATION_90, etc.
@@ -141,15 +142,18 @@ public abstract class WindowOrientationListener {
// however, we enforce stricter thresholds, pushing the thresholds 15 degrees closer to 180.
private final int[][][] THRESHOLDS = new int[][][] {
{{60, 180}, {180, 300}},
- {{0, 45}, {45, 165}, {330, 360}},
- {{0, 30}, {195, 315}, {315, 360}}
+ {{0, 45}, {45, 165}, {165,225}, {330, 360}},
+ {{0, 30}, {145,195}, {195,315}, {315, 360}},
+ {{0, 45}, {45,165}, {165,225}, {225, 360}}
};

// See THRESHOLDS
private final int[][] ROTATE_TO = new int[][] {
{ROTATION_270, ROTATION_90},
- {ROTATION_0, ROTATION_270, ROTATION_0},
- {ROTATION_0, ROTATION_90, ROTATION_0}
+ {ROTATION_0, ROTATION_270, ROTATION_180, ROTATION_0},
+ {ROTATION_0, ROTATION_180, ROTATION_90, ROTATION_0},
+ {ROTATION_0, ROTATION_270, ROTATION_180, ROTATION_90}
+ //{ROTATION_270, ROTATION_90}
};

// Maximum absolute tilt angle at which to consider orientation changes. Beyond this (i.e.
@@ -159,7 +163,7 @@ public abstract class WindowOrientationListener {
// Additional limits on tilt angle to transition to each new orientation. We ignore all
// vectors with tilt beyond MAX_TILT, but we can set stricter limits on transition to a
// particular orientation here.
- private final int[] MAX_TRANSITION_TILT = new int[] {MAX_TILT, MAX_TILT, MAX_TILT};
+ private final int[] MAX_TRANSITION_TILT = new int[] {MAX_TILT, MAX_TILT, MAX_TILT, MAX_TILT};
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值