zoukankan      html  css  js  c++  java
  • Android无线测试之—UiAutomator UiDevice API介绍五

    屏幕旋转

    一、屏幕旋转相关知识:

    1)旋转方向:0度,90度(向左转),180度,270度(向右转)

    2)重力感应器:重力感应器是旋转所依靠的

    3)固定位置:指将屏幕方向固定在0度,90度或者180度等

    4)物理旋转:物理旋转与重力感应器关联在一块,关闭物理旋转就是关闭了重力感应器,反之亦然)

    二、旋转屏幕相关API:

    返回值 方法名 描述
    void setOrientationLeft() 通过禁用传感器,然后模拟设备向左转,并且固定位置
    void setOrientationNatural() 通过禁用传感器,然后模拟设备转到其自然默认的方向,并且固定位置
    void setOrientationRight() 通过禁用传感器,然后模拟设备向右转,并且固定位置
    void unfreezeRotation() 重新启动传感器和允许物理旋转
    boolean isNaturalOrientation() 检测设备是否处于默认旋转状态
    int getDisplayRotation()

    返回当前的显示旋转,0度,90度,180度,270度值分别为:0、1、2、3

    void freezeRotation() 禁用传感器和冻结装置物理旋转在其当前旋转状态

    三、API应用举例:

    package com.UiAutomator;
    
    import java.io.File;
    
    import android.os.Bundle;
    import android.os.RemoteException;
    import android.view.KeyEvent;
    
    import com.android.uiautomator.core.UiDevice;
    import com.android.uiautomator.testrunner.UiAutomatorTestCase;
    
    public class Test1 extends UiAutomatorTestCase {
        
        public void testOrientation() throws RemoteException{
            
            int r=UiDevice.getInstance().getDisplayRotation();
            if(r==0){
                System.out.println("r="+r);
                UiDevice.getInstance().setOrientationLeft();
            }
            if(r==1){
                UiDevice.getInstance().setOrientationNatural();
                sleep(1000);
                UiDevice.getInstance().setOrientationLeft();
            }
            if(r==2){
                UiDevice.getInstance().setOrientationNatural();
                sleep(1000);
                UiDevice.getInstance().setOrientationLeft();
            }
            if(r==3){
                UiDevice.getInstance().setOrientationNatural();
            }
            
        }
    
    }
    Test.java
  • 相关阅读:
    sparkSQL
    Spark分区实例(teacher)
    SparkCore的性能优化
    Linux 输出当前路径下某个文件的绝对路径
    bulid runnable jar file with dependencies
    bulid runnable jar file with dependencies and main class
    spring mvc 整合jsp和thymeleaf两个模板引擎
    解决Volley中的JsonObjectRequest jsonRequest参数无法被服务端读取的问题
    为volley的http请求添加自定义request header
    使用spring-boot-starter-data-jpa 怎么配置使运行时输出SQL语句
  • 原文地址:https://www.cnblogs.com/fsw-blog/p/4546302.html
Copyright © 2011-2022 走看看