---
title: "virtual<二>"
author: "ping8080"
date: "2011-10-18T10:43:11Z"
tags: []
categories: ["移动开发"]
slug: "virtual"
draft: false
lastmod: "2011-10-18T11:17:09Z"
id: 1199027
url: "https://ping8080.iteye.com/blog/1199027"
---

改动文件如下

 

froyo/frameworks/base/api/current.xml

line 167996 修改如下

 

 &lt;method name="getHeight"  
 return="int"  
 abstract="false"  
 native="false"  
 synchronized="false"  
 static="false"  
 final="false"  
 deprecated="not deprecated"  
 visibility="public"  
&gt;  
&lt;/method&gt;  
&lt;method name="getHeightWithPanel"  
 return="int"  
 abstract="false"  
 native="true"  
 synchronized="false"  
 static="false"  
 final="false"  
 deprecated="not deprecated"  
 visibility="public"  
&gt;

 

line 168075 修改如下

 

&lt;method name="getWidth"  
 return="int"  
 abstract="false"  
 native="false"  
 synchronized="false"  
 static="false"  
 final="false"  
 deprecated="not deprecated"  
 visibility="public"  
&gt;  
&lt;/method&gt;  
&lt;method name="getWidthWithPanel"  
 return="int"  
 abstract="false"  
 native="true"  
 synchronized="false"  
 static="false"  
 final="false"  
 deprecated="not deprecated"  
 visibility="public"  
&gt;

 

froyo\\frameworks\\base\\core\\java\\android\\view\\Display.java

 

line 69  

把native public int getWidth(); 改成 如下方法

    public int getWidth() {  
        if(getWidthWithPanel() &gt; getHeightWithPanel()){  
            return getWidthWithPanel() - 40;  
        }else{  
            return getWidthWithPanel();  
        }         
    }

并且加入此方法：

    native public int getWidthWithPanel();

 

 

line 87

把native public int getHeight();改成如下方法

 public int getHeight() {  
        if(getWidthWithPanel() &gt; getHeightWithPanel()){  
            return getHeightWithPanel();  
        }else{  
            return getHeightWithPanel() - 40;  
        }

    }

并加入

    native public int getHeightWithPanel();

 

froyo\\frameworks\\base\\core\\java\\android\\view\\IWindowManager.aidl

 

line 55 加入

boolean injectKeyEvent2(in KeyEvent ev, boolean sync);

 

froyo\\frameworks\\base\\core\\jni\\android\_view\_Display.cpp

 

line 108:

把 {   "getWidth", "()I", 改成 {   "getWidthWithPanel", "()I",

line 110:  
 把{   "getHeight", "()I", 改成 {   "getHeightWithPanel", "()I",

 

froyo\\frameworks\\base\\services\\java\\com\\android\\server\\InputDevice.java

 

line 838:

把

final int dispW = display.getWidth()-1;  
final int dispH = display.getHeight()-1;

改成

 final int dispW = display.getWidthWithPanel()-1;  
 final int dispH = display.getHeightWithPanel()-1;

 

 

froyo\\frameworks\\base\\services\\java\\com\\android\\server\\KeyInputQueue.java

 

line 51 加入 ：import android.util.Log;

 

line 1382 加入 方法:

 

    public void addLocked2(KeyEvent ev) {  
        Log.i(TAG, "addLocked2");  
        synchronized (mFirst) {  
            final int N = mDevices.size();  
            for (int i=0; i&lt;N; i++) {  
                InputDevice d = mDevices.valueAt(i);  
                if( (d != null) && ((d.classes&RawInputEvent.CLASS\_KEYBOARD) != 0) ) {  
                    addLocked(d, System.nanoTime(), 0, RawInputEvent.CLASS\_KEYBOARD, ev);  
                    Log.i(TAG, "addLocked2  .........");  
                    break;  
                }  
            }  
        }  
    }

 

froyo\\frameworks\\base\\services\\java\\com\\android\\server\\WindowManagerService.java

 

line 5528 :加入

    public boolean injectKeyEvent2(KeyEvent ev, boolean sync) {  
        mQueue.addLocked2(ev);  
        return true;  
    }

 

 

froyo\\frameworks\\base\\services\\java\\com\\android\\server\\status\\StatusBarService.java

 

line 70:加入

import android.graphics.Color;  
import android.widget.ImageView;

 

import android.os.ServiceManager;  
import android.util.Log;  
import android.view.IWindowManager;  
import android.view.KeyCharacterMap;  
import android.view.View.OnTouchListener;

 

line 98 :修改

把public class StatusBarService extends IStatusBar.Stub改成

public class StatusBarService extends IStatusBar.Stub implements OnTouchListener

 

line 244 加入：ImageView iv1, iv2, iv3, iv4;

 

line 364 加入：

        LinearLayout mSystemMenuBarView = (LinearLayout)View.inflate(mContext,  
                com.android.internal.R.layout.control\_panel, null);  
        mSystemMenuBarView.setBackgroundColor(Color.BLACK);  
        mSystemMenuBarView.setOrientation(LinearLayout.VERTICAL);  
        iv1 = (ImageView) mSystemMenuBarView.findViewById(R.id.panel1);  
        iv2 = (ImageView) mSystemMenuBarView.findViewById(R.id.panel2);  
        iv3 = (ImageView) mSystemMenuBarView.findViewById(R.id.panel3);  
        iv4 = (ImageView) mSystemMenuBarView.findViewById(R.id.panel4);  
        iv1.setOnTouchListener(this);  
        iv2.setOnTouchListener(this);  
        iv3.setOnTouchListener(this);  
        iv4.setOnTouchListener(this);

        WindowManager.LayoutParams lp1 = new WindowManager.LayoutParams(             
                ViewGroup.LayoutParams.MATCH\_PARENT,  
                ViewGroup.LayoutParams.MATCH\_PARENT,  
                WindowManager.LayoutParams.FIRST\_SYSTEM\_WINDOW + 20,  
                WindowManager.LayoutParams.FLAG\_NOT\_FOCUSABLE|//note by unic: this line of code make the activity content being in the front.  
                WindowManager.LayoutParams.FLAG\_TOUCHABLE\_WHEN\_WAKING,  
                PixelFormat.TRANSLUCENT);  
//            lp1.gravity = Gravity.RIGHT | Gravity.FILL\_VERTICAL;  
        lp1.setTitle("systemMenuBar");

        WindowManagerImpl.getDefault().addView(mSystemMenuBarView, lp1);

 

 

line 1880加入：

 

  public boolean onTouch(View v, MotionEvent event) {  
  if (event.getAction() == MotionEvent.ACTION\_DOWN) {  
            if (mDisplay.getWidth() &gt; mDisplay.getHeight()) {  
       switch (v.getId()) {  
        case R.id.panel1:                     
                        iv1.setImageResource(R.drawable.panel\_back\_pressed);                     
         new Thread(new RunKey(KeyEvent.KEYCODE\_BACK, KeyEvent.ACTION\_DOWN)).start();  
         break;      
        case R.id.panel2:  
                        iv2.setImageResource(R.drawable.panel\_search\_pressed);  
         new Thread(new RunKey(KeyEvent.KEYCODE\_SEARCH, KeyEvent.ACTION\_DOWN)).start();  
         break;  
        case R.id.panel3:  
                        iv3.setImageResource(R.drawable.panel\_menu\_pressed);  
         new Thread(new RunKey(KeyEvent.KEYCODE\_MENU, KeyEvent.ACTION\_DOWN)).start();  
         break;       
        case R.id.panel4:  
                        iv4.setImageResource(R.drawable.panel\_home\_pressed);                     
         new Thread(new RunKey(KeyEvent.KEYCODE\_HOME, KeyEvent.ACTION\_DOWN)).start();  
         break;  
       }  
            }else{  
                switch (v.getId()) {  
        case R.id.panel1:                     
                        iv1.setImageResource(R.drawable.panel\_home\_pressed);                     
         new Thread(new RunKey(KeyEvent.KEYCODE\_HOME, KeyEvent.ACTION\_DOWN)).start();  
         break;  
        case R.id.panel2:  
                        iv2.setImageResource(R.drawable.panel\_menu\_pressed);  
         new Thread(new RunKey(KeyEvent.KEYCODE\_MENU, KeyEvent.ACTION\_DOWN)).start();  
         break;  
        case R.id.panel3:  
                        iv3.setImageResource(R.drawable.panel\_search\_pressed);  
         new Thread(new RunKey(KeyEvent.KEYCODE\_SEARCH, KeyEvent.ACTION\_DOWN)).start();                
         break;       
        case R.id.panel4:  
                       iv4.setImageResource(R.drawable.panel\_back\_pressed);                     
         new Thread(new RunKey(KeyEvent.KEYCODE\_BACK, KeyEvent.ACTION\_DOWN)).start();  
                        break;          
                }  
            }         
  }  
         
  if (event.getAction() == MotionEvent.ACTION\_UP) {  
            if (mDisplay.getWidth() &gt; mDisplay.getHeight()) {  
       switch (v.getId()) {  
        case R.id.panel1:  
                        iv1.setImageResource(R.drawable.panel\_back);                     
         new Thread(new RunKey(KeyEvent.KEYCODE\_BACK, KeyEvent.ACTION\_UP)).start();  
         break;      
        case R.id.panel2:  
                        iv2.setImageResource(R.drawable.panel\_search);                     
         new Thread(new RunKey(KeyEvent.KEYCODE\_SEARCH, KeyEvent.ACTION\_UP)).start();  
         break;  
        case R.id.panel3:  
                        iv3.setImageResource(R.drawable.panel\_menu);  
         new Thread(new RunKey(KeyEvent.KEYCODE\_MENU, KeyEvent.ACTION\_UP)).start();  
         break;       
        case R.id.panel4:  
                        iv4.setImageResource(R.drawable.panel\_home);  
         new Thread(new RunKey(KeyEvent.KEYCODE\_HOME, KeyEvent.ACTION\_UP)).start();  
         break;  
       }  
            }else {  
       switch (v.getId()) {  
        case R.id.panel1:  
                        iv1.setImageResource(R.drawable.panel\_home);  
         new Thread(new RunKey(KeyEvent.KEYCODE\_HOME, KeyEvent.ACTION\_UP)).start();  
         break;      
        case R.id.panel2:  
                        iv2.setImageResource(R.drawable.panel\_menu);  
                        new Thread(new RunKey(KeyEvent.KEYCODE\_MENU, KeyEvent.ACTION\_UP)).start();

         break;  
        case R.id.panel3:  
                        iv3.setImageResource(R.drawable.panel\_search);                     
         new Thread(new RunKey(KeyEvent.KEYCODE\_SEARCH, KeyEvent.ACTION\_UP)).start();  
         break;       
        case R.id.panel4:  
                        iv4.setImageResource(R.drawable.panel\_back);                     
         new Thread(new RunKey(KeyEvent.KEYCODE\_BACK, KeyEvent.ACTION\_UP)).start();  
         break;  
                 }             
            }  
  }  
  return true;  
 }  
     
    private class RunKey implements Runnable{  
  int code;  
        int type;  
    
  public void run() {        
   long now = SystemClock.uptimeMillis();        
   try {  
             KeyEvent down = new KeyEvent(now, now, type, code, 0);              
             (IWindowManager.Stub  
                 .asInterface(ServiceManager.getService("window")))  
                 .injectKeyEvent2(down, true);                 
         } catch (RemoteException e) {  
             Log.i("Input", "DeadOjbectException");  
         }  
     }  
  

        public RunKey (int keycode, int actionType){  
         this.code = keycode;  
            this.type = actionType;  
        }  
    }  

 

froyo\\frameworks\\policies\\base\\phone\\com\\android\\internal\\policy\\impl\\PhoneWindowManager.java

 

 

line 194 ： 加入    WindowState mSystemMenuBar = null;   

 

 

line 766 :在 方法 public int windowTypeToLayerLw(int type) 中加入

 

case TYPE\_STATUS\_BAR + 20:  
            return STATUS\_BAR\_LAYER + 20;

 

line 960 ：在方法 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs)

中加入

 

 

case TYPE\_STATUS\_BAR + 20:  
                if (mSystemMenuBar != null) {  
                    return WindowManagerImpl.ADD\_MULTIPLE\_SINGLETON;  
                }  
                mSystemMenuBar = win;  
                break;

 

 

 

line 992 : 在方法 public void removeWindowLw(WindowState win)中 加入

 

else if (mSystemMenuBar == win) {  
            mSystemMenuBar = null;  
        }

 

 

 

line 1251 在方法 public void beginLayoutLw(int displayWidth, int displayHeight 中加入

 

final Rect pf = mTmpParentFrame;  
        final Rect df = mTmpDisplayFrame;  
        final Rect vf = mTmpVisibleFrame;  
        pf.left = df.left = vf.left = 0;  
        pf.top = df.top = vf.top = 0;  
        pf.right = df.right = vf.right = displayWidth;         
        pf.bottom = df.bottom = vf.bottom = displayHeight;         
           

 

 

并且 把

 

if (mStatusBar != null) {  
            final Rect pf = mTmpParentFrame;  
            final Rect df = mTmpDisplayFrame;  
            final Rect vf = mTmpVisibleFrame;  
            pf.left = df.left = vf.left = 0;  
            pf.top = df.top = vf.top = 0;  
            pf.right = df.right = vf.right = displayWidth;  
            pf.bottom = df.bottom = vf.bottom = displayHeight;  
             
            mStatusBar.computeFrameLw(pf, df, vf, vf);

改成

 if (mStatusBar != null) {  
            mStatusBar.computeFrameLw(pf, df, vf, vf);

 

 

并在 line 1270  加入（加到方法beginLayoutLw中）

 

       if (displayWidth &gt; displayHeight) {  
            pf.left = df.left = vf.left = displayWidth;  
            pf.right = df.right = vf.right = displayWidth + 40;  
        } else {  
            pf.top = df.top = vf.top = displayHeight;  
            pf.bottom = df.bottom = vf.bottom = displayHeight + 40;  
        }   

        if (mSystemMenuBar != null) {     
            mSystemMenuBar.computeFrameLw(pf, df, vf, vf);  
        }   

 

 

 

line 1348  在方法 public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,  
            WindowState attached) 中 加入 (line 1355)

 

if (win == mSystemMenuBar) {  
            return;  
        }