Example of adding a global TouchPanel for android

Source: Internet
Author: User
Tags gety

Example of adding a global TouchPanel for android

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 cbk private static final int Limit = 7; private static final int MSG_DISABLE_NAV_BAR_PULL_UP_GESTURE = 8; // end nav down by cbk private class PolicyHandler extends Handler {@ Override public 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 cbk case when: break (); break; case when: disablenavbarpullupgsture (); break; // end nav down by c Bk }}class SettingsObserver extends ContentObserver {SettingsObserver (Handler handler) {super (handler);} void observe () {// Observe all users 'changes ContentResolver resolver = mContext. getContentResolver (); // Add nav down by cbk resolver. registerContentObserver (Settings. system. getUriFor (Settings. system. MULTI_TOUCH_GESTURE), false, this, UserHandle. USER_ALL); // end nav down by cbk updateSe Ttings () ;}@ 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 cbk if (FeatureOption. k19_NCX_ASSISTIVE_TOUCH_NAV_BAR) {/* int NavBarPullupGesture = Settings. system. getIntForUser (resolver, Sett Ings. System. MULTI_TOUCH_GESTURE, 0, UserHandle. USER_CURRENT); if (mnavbarpullupgsturemode! = Navbarpullupgsture) {mnavbarpullupgsturemode = navbarpullupgsture; mHandler. sendEmptyMessage (navbarpullupgsture! = 0? MSG_ENABLE_NAV_BAR_PULL_UP_GESTURE: MSG_DISABLE_NAV_BAR_PULL_UP_GESTURE);} */if (mnavbarpullupgsturemode! = 1) {mnavbarpullupgsturemode = 1; mHandler. sendEmptyMessage (callback) ;}// end nav down by cbk }// Add nav down by cbk int mnavbarpullupgsturemode = 0; navbarpullupgsturepanel mnavbarpullupgstureview; InputChannel resume; static final String TAG_NAV_BAR_PULL_UP_G ESTURE = "navbarpullupgsture"; 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 navbarpullupgstureinputeventreceiver extends InputEventReceiver {private final navbarpullupgsturepanel mView; public navbarpullupgsture6b UtEventReceiver (InputChannel inputChannel, loopetemediaview) {super (inputChannel, loopchannel); mView = view ;}@ Override public 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, "NavBarDispla YGesture () "); statusBarService. enableNavBarDisplay (); // togglavbardisplay ();} catch (RemoteException e) {Log. e (TAG, "Error toggling recent apps. ") ;}} public class navbarpullupgsturepanel extends FrameLayout {public navbarpullupgsturepanel (Context context) {super (context) ;}@ Override public boolean onTouchEvent (MotionEvent event) {// TODO Auto-generated method stub if (DEBUG_NAV_BAR_PULL _ UP_GESTURE) Log. d (TAG_NAV_BAR_PULL_UP_GESTURE, "navbarpullupgsturepanel 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, "navbarpullupgsturepanel tp_down mPosX =" + mPosX + ", mPosY =" + mPosY);} else if (MotionEvent. ACTION_MOVE = ev Ent. getAction () {mCurrentPosX = (int) event. getX (); mCurrentPosY = (int) event. getY (); if (DEBUG_NAV_BAR_PULL_UP_GESTURE) Log. d (optional, "required 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, "NavBarP Ullupgsturepanel 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, "Push up position" + mPosX + "move position" + 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 (dependencies, "navbarpullupgsturepanel tp_down mPosX =" + mPosX + ", mPosY =" + mPosY + ", orientation =" + orientation); if (orientation = Configuration. ORIENTATION_LANDSCAPE) {if (mPosY> = 540 & mPosY <= 600) {NavBarDisp LayGesture () ;}} else if (orientation = Configuration. ORIENTATION_PORTRAIT) {if (mPosY> = 940 & mPosY <= 1024) {NavBarDisplayGesture () ;}}return true ;}@ Override public boolean onGenericMotionEvent (MotionEvent) {final int source = event. getSource ();/* if (source & InputDevice. SOURCE_CLASS_POINTER )! = 0) {mGestureRecognizer. onTouchEvent (event);} */return true;} private void upload () {if (mnavbarpullupgstureview = null) {mnavbarpullupgstureview = new navbarpullupgsturepanel (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 ("navbarpullupgsturepanel"); WindowManager wm = (WindowManager) mContext. getSystemService (Context. WINDOW_SERVICE); wm. ad DView (mnavbarpullupgstureview, lp); if (DEBUG_NAV_BAR_PULL_UP_GESTURE) Log. d (TAG_NAV_BAR_PULL_UP_GESTURE, "enablenavbarpullupgsture"); mnavbarpullupgstureinputchannel = mWindowManagerFuncs. monitorInput ("navbarpullupgsture"); mnavbarpullupgstureinputeventreceiver = new navbarpullupgstureinputeventventer (mnavbarpullupgstureinputchannel, Looper. myLooper (), mnavbarpullupgstureview);} priva Te void disablenavbarpullupgsture () {if (latency) Log. d (TAG_NAV_BAR_PULL_UP_GESTURE, "disablenavbarpullupgsture"); if (mnavbarpullupgstureinputeventreceiver! = Null) {mnavbarpullupgstureinputeventreceiver. dispose (); mnavbarpullupgstureinputeventventer = null;} if (mnavbarpullupgstureinputchannel! = Null) {mnavbarpullupgstureinputchannel. dispose (); mnavbarpullupgstureinputchannel = null;} if (mnavbarpullupgstureview! = Null) {WindowManager wm = (WindowManager) mContext. getSystemService (Context. WINDOW_SERVICE); wm. removeView (mnavbarpullupgstureview); mnavbarpullupgstureview = null; }}// end nav down by cbk}


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.