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,些許的拉伸不會影響顯示效果。

二.frameworks\base\services\core\java\com\android\server\display\LogicalDisplay.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;
                }
            }
        }

 雙屏屬性

# Dual - display configuration 
# 主屏 eDP
sys.hwc.device.primary=eDP
# 副屏
sys.hwc.device.extend=LVDS 
#persist.sys.framebuffer.main=800x1280
persist.sys.resolution.main=1920x1080
persist.sys.resolution.aux=800x1280

#  副屏是否全屏顯示
persist.sys.rotation.efull = true

# 主屏的旋轉方向(0 90 180 270)
ro.sf.hwrotation=0

# 副屏輸出旋轉方向對應 0 / 90 / 180 / 270(0 1 2 3)
+persist.sys.rotation.einit =1

#副屏也隨着 g-sensor 旋轉(只關注方向,黑邊不關注)
ro.sys.rotation.sensor =false

// 主副屏orientaion是否相同
ro.same.orientation=false

// 副屏是否隨主屏旋轉
ro.rotation.external=false

  

 三.寫了個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 + "\n");
			os.writeBytes("exit\n");
			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) {
			}
		}
	}
}

  

  

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM