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) {
    			}
    		}
    	}
    }
    

      

      

      

  • 相关阅读:
    技术网址收藏
    解决IE兼容模式的方案
    C/S通信模型与B/S通信模型介绍
    asp.net 常用于客户端注册的机器信息
    Ado.Net,关于DataSet和DataTable
    WinForm程序开发
    发送邮件-成功
    css背景全屏-视差
    ASP.NET中的随机密码生成
    javascript 替换 window.onload 的 document.ready
  • 原文地址:https://www.cnblogs.com/crushgirl/p/14864109.html
Copyright © 2011-2022 走看看