android 添加全局TouchPanel响应范例

alps\frameworks\base\policy\src\com\android\internal\policy\impl\PhoneWindowManager.java

package com.android.internal.policy.impl;public class PhoneWindowManager implements WindowManagerPolicy {private static final int MSG_ENABLE_POINTER_LOCATION = 1;private static final int MSG_DISABLE_POINTER_LOCATION = 2;//Add nav down by cbkprivate static final int MSG_ENABLE_NAV_BAR_PULL_UP_GESTURE = 7;private static final int MSG_DISABLE_NAV_BAR_PULL_UP_GESTURE = 8;//end nav down by cbkprivate class PolicyHandler extends Handler {@Overridepublic void handleMessage(Message msg) {switch (msg.what) {case MSG_ENABLE_POINTER_LOCATION:enablePointerLocation();break;case MSG_DISABLE_POINTER_LOCATION:disablePointerLocation();break;//Add nav down by cbkcase MSG_ENABLE_NAV_BAR_PULL_UP_GESTURE:enableNavBarPullupGesture();break;case MSG_DISABLE_NAV_BAR_PULL_UP_GESTURE:disableNavBarPullupGesture();break;//end nav down by cbk}}}class SettingsObserver extends ContentObserver {SettingsObserver(Handler handler) {super(handler);}void observe() {// Observe all users' changesContentResolver resolver = mContext.getContentResolver();//Add nav down by cbkresolver.registerContentObserver(Settings.System.getUriFor(Settings.System.MULTI_TOUCH_GESTURE), false, this,UserHandle.USER_ALL);//end nav down by cbkupdateSettings();}@Override public void onChange(boolean selfChange) {updateSettings();updateRotation(false);}}public void updateSettings() {ContentResolver resolver = mContext.getContentResolver();boolean updateRotation = false;synchronized (mLock) {//Add nav down by cbkif (FeatureOption.K19_NCX_ASSISTIVE_TOUCH_NAV_BAR) {/*int NavBarPullupGesture = Settings.System.getIntForUser(resolver,Settings.System.MULTI_TOUCH_GESTURE, 0, UserHandle.USER_CURRENT);if (mNavBarPullupGestureMode != NavBarPullupGesture) {mNavBarPullupGestureMode = NavBarPullupGesture;mHandler.sendEmptyMessage(NavBarPullupGesture != 0 ?MSG_ENABLE_NAV_BAR_PULL_UP_GESTURE: MSG_DISABLE_NAV_BAR_PULL_UP_GESTURE);}*/if (mNavBarPullupGestureMode != 1) {mNavBarPullupGestureMode = 1;mHandler.sendEmptyMessage(MSG_ENABLE_NAV_BAR_PULL_UP_GESTURE);}}//end nav down by cbk}}//Add nav down by cbkint mNavBarPullupGestureMode = 0;NavBarPullupGestureInputEventReceiver mNavBarPullupGestureInputEventReceiver;NavBarPullupGesturePanel mNavBarPullupGestureView;InputChannel mNavBarPullupGestureInputChannel;static final String TAG_NAV_BAR_PULL_UP_GESTURE = "NavBarPullupGesture";static boolean DEBUG_NAV_BAR_PULL_UP_GESTURE = true;private int mPosX =0;private int mPosY =0;private int mCurrentPosX =0;private int mCurrentPosY =0;private boolean mNavBarPullUpValid = false;private static final class NavBarPullupGestureInputEventReceiver extends InputEventReceiver {private final NavBarPullupGesturePanel mView;public NavBarPullupGestureInputEventReceiver(InputChannel inputChannel, Looper looper,NavBarPullupGesturePanel view) {super(inputChannel, looper);mView = view;}@Overridepublic void onInputEvent(InputEvent event) {boolean handled = false;try {if (event instanceof MotionEvent&& (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {final MotionEvent motionEvent = (MotionEvent)event;mView.onTouchEvent(motionEvent);handled = true;}} finally {finishInputEvent(event, handled);}}}public void NavBarDisplayGesture() {IStatusBarService statusBarService = IStatusBarService.Stub.asInterface(ServiceManager.getService("statusbar"));try {if (DEBUG_NAV_BAR_PULL_UP_GESTURE) Log.d(TAG_NAV_BAR_PULL_UP_GESTURE,"NavBarDisplayGesture ()");statusBarService.EnableNavBarDisplay();//toggleNavBarDisplay();} catch (RemoteException e) {Log.e(TAG, "Error toggling recent apps.");}}public class NavBarPullupGesturePanel extends FrameLayout{public NavBarPullupGesturePanel(Context context) {super(context);}@Overridepublic boolean onTouchEvent(MotionEvent event) {// TODO Auto-generated method stub if (DEBUG_NAV_BAR_PULL_UP_GESTURE) Log.d(TAG_NAV_BAR_PULL_UP_GESTURE,"NavBarPullupGesturePanel event.getAction() =" +event.getAction() );/*if(MotionEvent.ACTION_DOWN==event.getAction()){ mPosX = (int)event.getX(); mPosY = (int)event.getY();if (DEBUG_NAV_BAR_PULL_UP_GESTURE)Log.d(TAG_NAV_BAR_PULL_UP_GESTURE,"NavBarPullupGesturePanel tp_down mPosX =" +mPosX+",mPosY ="+mPosY);}else if (MotionEvent.ACTION_MOVE == event.getAction()) { mCurrentPosX = (int)event.getX(); mCurrentPosY = (int)event.getY();if (DEBUG_NAV_BAR_PULL_UP_GESTURE)Log.d(TAG_NAV_BAR_PULL_UP_GESTURE,"NavBarPullupGesturePanel tp_move mCurrentPosX =" +mCurrentPosX+",mCurrentPosY ="+mCurrentPosY); }else{ mCurrentPosX = 0; mCurrentPosY = 0; mPosX = 0; mPosY = 0; } if (DEBUG_NAV_BAR_PULL_UP_GESTURE) Log.d(TAG_NAV_BAR_PULL_UP_GESTURE,"NavBarPullupGesturePanel mPosX =" +mPosX+ ",mPosY ="+mPosY+ ",mCurrentPosX ="+mCurrentPosX+ ",mCurrentPosY ="+mCurrentPosY ); if (mCurrentPosY – mPosY < -200 && Math.abs(mCurrentPosX – mPosX) < 300) { NavBarDisplayGesture(); Log.d(TAG_NAV_BAR_PULL_UP_GESTURE, "向上的按下位置"+mPosX+"移动位置"+mCurrentPosX); }*/ if(MotionEvent.ACTION_DOWN==event.getAction()){ mPosX = (int)event.getX(); mPosY = (int)event.getY();int orientation = mContext.getResources().getConfiguration().orientation;Log.d(TAG,"current config orienation " + orientation);if (DEBUG_NAV_BAR_PULL_UP_GESTURE)Log.d(TAG_NAV_BAR_PULL_UP_GESTURE,"NavBarPullupGesturePanel tp_down mPosX =" +mPosX+",mPosY ="+mPosY+",orientation =" +orientation);if (orientation == Configuration.ORIENTATION_LANDSCAPE) {if(mPosY >=540 && mPosY <=600){NavBarDisplayGesture();}}else if(orientation == Configuration.ORIENTATION_PORTRAIT) {if(mPosY >=940 && mPosY <=1024){NavBarDisplayGesture();} } }return true;}@Overridepublic boolean onGenericMotionEvent(MotionEvent event) {final int source = event.getSource();/*if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) {mGestureRecognizer.onTouchEvent(event);}*/return true;}}private void enableNavBarPullupGesture() {if (mNavBarPullupGestureView == null) {mNavBarPullupGestureView = new NavBarPullupGesturePanel(mContext);WindowManager.LayoutParams lp = new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.MATCH_PARENT);lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;lp.format = PixelFormat.TRANSLUCENT;lp.setTitle("NavBarPullupGesturePanel");WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);wm.addView(mNavBarPullupGestureView, lp);if (DEBUG_NAV_BAR_PULL_UP_GESTURE) Log.d(TAG_NAV_BAR_PULL_UP_GESTURE,"enableNavBarPullupGesture");mNavBarPullupGestureInputChannel =mWindowManagerFuncs.monitorInput("NavBarPullupGesture");mNavBarPullupGestureInputEventReceiver =new NavBarPullupGestureInputEventReceiver(mNavBarPullupGestureInputChannel,Looper.myLooper(), mNavBarPullupGestureView);}}private void disableNavBarPullupGesture() {if (DEBUG_NAV_BAR_PULL_UP_GESTURE) Log.d(TAG_NAV_BAR_PULL_UP_GESTURE,"disableNavBarPullupGesture");if (mNavBarPullupGestureInputEventReceiver != null) {mNavBarPullupGestureInputEventReceiver.dispose();mNavBarPullupGestureInputEventReceiver = null;}if (mNavBarPullupGestureInputChannel != null) {mNavBarPullupGestureInputChannel.dispose();mNavBarPullupGestureInputChannel = null;}if (mNavBarPullupGestureView != null) {WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);wm.removeView(mNavBarPullupGestureView);mNavBarPullupGestureView = null;}}//end nav down by cbk}

,发光并非太阳的专利,你也可以发光

android 添加全局TouchPanel响应范例

相关文章:

你感兴趣的文章:

标签云: