zoukankan      html  css  js  c++  java
  • RK Android7.1 双屏显示旋转方向

     一.参考 Rockchip_Developer_Guide_Dual_Display_Rotation_Direction_Debugging_CN.pdf

    persist.sys.rotation.einit = 0 / 1 / 2 / 3:
    persist.sys.rotation.efull = false / true:
    备注:当主副屏宽高比不同时,persist.sys.rotation.efull 为 false,则副屏会出现黑边, 
    所以这种情况,建议将 persist.sys.rotation.efull 设置为 true,些许的拉伸不会影响显示效果。

    二.frameworksaseservicescorejavacomandroidserverdisplayLogicalDisplay.java

        public DisplayInfo getDisplayInfoLocked() {
            if (mInfo == null) {
                mInfo = new DisplayInfo();
                mInfo.copyFrom(mBaseDisplayInfo);
                if (mOverrideDisplayInfo != null) {
                    mInfo.appWidth = mOverrideDisplayInfo.appWidth;
                    mInfo.appHeight = mOverrideDisplayInfo.appHeight;
                    mInfo.smallestNominalAppWidth = mOverrideDisplayInfo.smallestNominalAppWidth;
                    mInfo.smallestNominalAppHeight = mOverrideDisplayInfo.smallestNominalAppHeight;
                    mInfo.largestNominalAppWidth = mOverrideDisplayInfo.largestNominalAppWidth;
                    mInfo.largestNominalAppHeight = mOverrideDisplayInfo.largestNominalAppHeight;
                    mInfo.logicalWidth = mOverrideDisplayInfo.logicalWidth;
                    mInfo.logicalHeight = mOverrideDisplayInfo.logicalHeight;
                    mInfo.overscanLeft = mOverrideDisplayInfo.overscanLeft;
                    mInfo.overscanTop = mOverrideDisplayInfo.overscanTop;
                    mInfo.overscanRight = mOverrideDisplayInfo.overscanRight;
                    mInfo.overscanBottom = mOverrideDisplayInfo.overscanBottom;
                    mInfo.rotation = mOverrideDisplayInfo.rotation;
                    mInfo.logicalDensityDpi = mOverrideDisplayInfo.logicalDensityDpi;
                    mInfo.physicalXDpi = mOverrideDisplayInfo.physicalXDpi;
                    mInfo.physicalYDpi = mOverrideDisplayInfo.physicalYDpi;
                }
                if(mDisplayId!=Display.DEFAULT_DISPLAY){
                    String rotation = SystemProperties.get("persist.sys.rotation.einit","0");
                    if(Integer.valueOf(rotation)%2!=0) {
    
    
                        mInfo.appWidth = mPrimaryDisplayDeviceInfo.height;
                        mInfo.appHeight = mPrimaryDisplayDeviceInfo.width;
                        mInfo.logicalWidth = mPrimaryDisplayDeviceInfo.height;
                        mInfo.logicalHeight=mPrimaryDisplayDeviceInfo.width;
    
                    }else{
                        mInfo.appWidth = mPrimaryDisplayDeviceInfo.width;
                        mInfo.appHeight = mPrimaryDisplayDeviceInfo.height;
                        mInfo.logicalWidth = mPrimaryDisplayDeviceInfo.width;
                        mInfo.logicalHeight=mPrimaryDisplayDeviceInfo.height;
                    }
                }
            }
    

     三.写了个apk 控制属性 

    3.1.布局

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:gravity="center"
        tools:context="com.gatsby.systemdisplay.MainActivity" >
    	
    
           <Button
            android:id="@+id/btn1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="0"
            android:textSize="32sp" />
    
        <Button
            android:id="@+id/btn2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="90"
            android:textSize="32sp" />
    
        <Button
            android:id="@+id/btn3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="180"
            android:textSize="32sp" />
    
        <Button
            android:id="@+id/btn4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="270"
            android:textSize="32sp" />
        
        <TextView
            android:id="@+id/text1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello_world"
            android:textSize="200sp" />
    
    </LinearLayout>
    

    3.2.code

    package com.gatsby.systemdisplay;
    
    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import java.lang.reflect.Method;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.TextView;
    
    public class MainActivity extends Activity implements OnClickListener {
    	Button btn1, btn2, btn3, btn4;
    	TextView text1;
    	String rotation_einit;
    
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_main);
    
    		btn1 = (Button) findViewById(R.id.btn1);
    		btn2 = (Button) findViewById(R.id.btn2);
    		btn3 = (Button) findViewById(R.id.btn3);
    		btn4 = (Button) findViewById(R.id.btn4);
    		text1 = (TextView) findViewById(R.id.text1);
    
    		btn1.setOnClickListener(this);
    		btn2.setOnClickListener(this);
    		btn3.setOnClickListener(this);
    		btn4.setOnClickListener(this);
    
    		rotation_einit = getProperty("persist.sys.rotation.einit");
    		text1.setText(rotation_einit);
    	}
    
    	@Override
    	public void onClick(View v) {
    		// TODO Auto-generated method stub
    		switch (v.getId()) {
    		case R.id.btn1:
    			setProperty("persist.sys.rotation.einit", "0");
    			RootCommand("reboot");
    			break;
    		case R.id.btn2:
    			setProperty("persist.sys.rotation.einit", "1");
    			RootCommand("reboot");
    			break;
    		case R.id.btn3:
    			setProperty("persist.sys.rotation.einit", "2");
    			RootCommand("reboot");
    			break;
    		case R.id.btn4:
    			setProperty("persist.sys.rotation.einit", "3");
    			RootCommand("reboot");
    			break;
    		}
    	}
    
    	@SuppressWarnings("finally")
    	public String getProperty(String key) {
    		String value = "unknown";
    		try {
    			Class<?> c = Class.forName("android.os.SystemProperties");
    			Method get = c.getMethod("get", String.class, String.class);
    			value = (String) (get.invoke(c, key, "unknown"));
    		} catch (Exception e) {
    			e.printStackTrace();
    		} finally {
    			return value;
    		}
    	}
    
    	public void setProperty(String key, String value) {
    		try {
    			Class<?> c = Class.forName("android.os.SystemProperties");
    			Method set = c.getMethod("set", String.class, String.class);
    			set.invoke(c, key, value);
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	public void RootCommand(String cmd) {
    		Process process = null;
    		DataOutputStream os = null;
    		DataInputStream is = null;
    		try {
    			process = Runtime.getRuntime().exec("su");
    			os = new DataOutputStream(process.getOutputStream());
    			os.writeBytes(cmd + "
    ");
    			os.writeBytes("exit
    ");
    			os.flush();
    			int aa = process.waitFor();
    			is = new DataInputStream(process.getInputStream());
    			byte[] buffer = new byte[is.available()];
    			is.read(buffer);
    			String out = new String(buffer);
    		} catch (Exception e) {
    			e.printStackTrace();
    		} finally {
    			try {
    				if (os != null) {
    					os.close();
    				}
    				if (is != null) {
    					is.close();
    				}
    				process.destroy();
    			} catch (Exception e) {
    			}
    		}
    	}
    }
    

      

      

      

  • 相关阅读:
    ionic3使用@angular/http 访问nodejs(koa2框架)服务不能返回数据
    FacebookFriendAdderPro
    SEO记录-1
    thanos 实现 prometheus 高可用 数据持久化2
    Prometheus + consul + grafana 监控体系搭建1
    解决问题方法
    原则设定
    docker-基本概念、架构和使用
    如何有效学习
    社会~
  • 原文地址:https://www.cnblogs.com/crushgirl/p/14864109.html
Copyright © 2011-2022 走看看