Aandroid-viewpager Source Code Analysis

Source: Internet
Author: User

 public boolean executekeyevent (keyevent event)  {         boolean handled = false;        if  ( Event.getaction ()  == keyevent.action_down)  {             switch  (Event.getkeycode ())  {                 case KeyEvent.KEYCODE_DPAD_LEFT: //  left.                      handled = arrowscroll (Focus_left); //                     break;                 case keyevent.keycode_dpad_right:                     handled =  Arrowscroll (focus_right); //  right .                     break;                 case KeyEvent.KEYCODE_TAB: //                      if   (BUILD.VERSION.SDK_INT >= 11)  {                         // The  focus finder had a bug handling focus_forward and focus_backward                          // before android 3.0. ignore the tab key on those  devices.                         if  (Keyeventcompat.hasnomodifiers (event))  {                              handled = arrowscroll (FOCUS_FORWARD);                          } else if  (Keyeventcompat.hasmodifiers (Event, keyevent.meta_shift_ ON))  {                             handled = arrowscroll (FOCUS_ backward);                          }                     }                     break;             }        }         return handled;    }

###

Public boolean arrowscroll (int direction)  {         view currentfocused = findfocus (); //  Find Focus .           if  (currentfocused == this)  { //  The current focus is  viewpager.             currentFocused = null;         } else if  (currentfocused != null)  {  // page1, page2, page3... ...             boolean isChild = false;   //             for  (viewparent parent =  Currentfocused.getparent (); parent instanceof viewgroup;                     parent = parent.getparent ())  {                 if  (Parent == this)  { //  if the parent of the focus child control is viewpager.                     isChild = true;                     break;                 }             }             if  (!ischild)  {                 // This would cause the focus search down  below to fail in fun ways.                 final stringbuilder sb = new stringbuilder ();                 sb.append (CurrentFocused.getClass (). Getsimplename ());                 for  (Viewparent parent = currentfocused.getparent ();  parent instanceof  ViewGroup;                         parent = parent.getparent ())  {                      sb.append (" => "). Append (Parent.getclass (). Getsimplename ());                 }                 LOG.E (tag,  "Arrowscroll tried to find focus based on  non-child  " +                          "current focused view "   + sb.tostring ());                 currentFocused = null; //  is not a focus control within this Viewpager .             }        }
        boolean handled = false;     //  get   Next focus .  like: nextfocusright....         View nextfocused = focusfinder.getinstance (). Findnextfocus (this, currentfocused,                 direction);             if  (nextfocused != null  && nextfocused != currentfocused)  {             if  (Direction == view.focus_left)  { //  left .                 // If  There is nothing to the left, or this is causing us to                 // jump to the right,  then what we really want to do is page left.                 final int nextleft  = getchildrectinpagercoordinates (mtemprect, nextfocused) .left;                 final int currLeft =  Getchildrectinpagercoordinates (mtemprect, currentfocused) .left;                 //    if  (currentfocused ! = null && nextleft >= currleft)  {                     handled =  Pageleft ();                 } else {                      Handled = nextfocused.requestfocus (); //                 }             } else if  (direction == view.focus_right)  {                 // if there is nothing  to the right, or this is causing us to                 // jump to the  left, then what we really want to do is page right.                 final int nextleft =  Getchildrectinpagercoordinates (mtemprect, nextfocused) .left;                 final int currLeft =  Getchildrectinpagercoordinates (mtemprect, currentfocused) .left;                 if  (currentfocused != null & & nextleft <= currleft)  {                     handled = pageright ();  //   page to the right.                 }  else {                     handled = nExtfocused.requestfocus ();                 }            }         } else if  (direction == focus_left | |  direction == focus_backward)  {             // Trying to move left and nothing there; try  to page.            handled =  Pageleft ();        } else if  (direction ==  focus_right | |  direction == focus_forward)  {             // trying to move right and nothing there; try to  page.  &nbsP;         handled = pageright ();         }        if  (handled)  {             playsoundeffect ( Soundeffectconstants.getcontantforfocusdirection (direction));         }         return handled;    }

###

Boolean pageright () {if (Madapter! = null && Mcuritem < (Madapter.getcount ()-1)) {Setcurren TItem (mcuritem+1, true);        return true;    } return false; }

###

Aandroid-viewpager Source Code Analysis

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.