公司想做一个半屏功能,就是下拉屏幕显示一半;刚开始在网上找了很久,都没有相关的经验可以借鉴;最后只能靠自己去源码里面寻找方法了; 不多说,直接上代码: 1)先上触发调用的方法 try { SystemProperties.set(“com.bsd.zoom.mode”,“1”); DisplayManager dm = (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE); Class<?> cDisplay = Class.forName(“android.hardware.display.DisplayManager”); Method singleHandMet = cDisplay.getMethod(“singleHandModeChange”, boolean.class, boolean.class); singleHandMet.invoke(dm, true,true); }catch (Exception e){ e.printStackTrace(); } (注:SystemProperties.set(“com.bsd.zoom.mode”,“1”);是判断半屏还是全屏,下面的放射方法是调用frameworks刷新界面)
2)frameworks\base\core\java\android\hardware\display\DisplayManager.java; 添加以下方法 public void singleHandModeChange(boolean change, boolean left){ mGlobal.singleHandModeChange(change,left); } 3)frameworks\base\core\java\android\hardware\display\DisplayManagerGlobal.java; 添加以下方法 public void singleHandModeChange(boolean change,boolean left){ try{ mDm.singleHandModeChange(change,left); }catch(RemoteException ex){ Log.w(“SingleHandMode”,“SingleHandMode Failed to singleHandChange error:”+ex.toString()); } } 4)frameworks\base\core\java\android\hardware\display\IDisplayManager.aidl; 添加以下方法: void singleHandModeChange(boolean change,boolean left); 5)frameworks\base\services\core\java\com\android\server\display\DisplayManagerService.java; 在BinderService内部类下添加: private final SurfaceControl.Transaction mDisplayTransaction = new SurfaceControl.Transaction(); @Override // Binder call public void singleHandModeChange(boolean change, boolean left) { // mSingleHandModeState = change; //mSingleHandModeLeft = left; scheduleTraversalLocked(false); performTraversalInternal(mDisplayTransaction); } 6)frameworks\base\services\core\java\com\android\server\wm\WindowStateAnimator.java; import android.os.SystemProperties; 在void setSurfaceBoundariesLocked(final boolean recoveringMemory)方法下 if (!w.mSeamlesslyRotated)判断语句内添加 if(SystemProperties.get(“com.bsd.zoom.mode”).equals(“1”)){ mTmpSize.top = 540; } //mSurfaceController.setPositionInTransaction(xOffset, yOffset, recoveringMemory); mSurfaceController.setPositionInTransaction(mTmpSize.left, mTmpSize.top, recoveringMemory); 7)frameworks\base\services\core\java\com\android\server\display\LogicalDisplay.java; 在configureDisplayLocked方法里添加 String zoomState = SystemProperties.get(“com.bsd.zoom.mode”); if(!zoomState.equals("") && zoomState != null){ if(zoomState.equals(“1”)){//降一半 mTempLayerStackRect.set(0, -displayInfo.logicalHeight/2, displayInfo.logicalWidth, displayInfo.logicalHeight/2); }else{//复原 mTempLayerStackRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight); } }else{ mTempLayerStackRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight); } 还有 int displayRectTop = (physHeight - displayRectHeight) / 2; int displayRectLeft = (physWidth - displayRectWidth) / 2;
if(!zoomState.equals("") && zoomState != null){
if(zoomState.equals("1")){//降一半-触摸
displayRectTop = displayRectHeight/2;
displayRectLeft = 0;
}
}
|