Example #1
0
  @Test
  public void shouldFocus() throws Exception {
    final Transcript transcript = new Transcript();

    view.setOnFocusChangeListener(
        new View.OnFocusChangeListener() {
          @Override
          public void onFocusChange(View v, boolean hasFocus) {
            transcript.add(hasFocus ? "Gained focus" : "Lost focus");
          }
        });

    assertFalse(view.isFocused());
    assertFalse(view.hasFocus());
    transcript.assertNoEventsSoFar();

    view.requestFocus();
    assertTrue(view.isFocused());
    assertTrue(view.hasFocus());
    transcript.assertEventsSoFar("Gained focus");

    view.clearFocus();
    assertFalse(view.isFocused());
    assertFalse(view.hasFocus());
    transcript.assertEventsSoFar("Lost focus");
  }
 /** {@inheritDoc} */
 public void onTouchModeChanged(boolean isInTouchMode) {
   if (!isInTouchMode) {
     // leaving touch mode.. if nothing has focus, let's give it to
     // the indicator of the current tab
     if (!mCurrentView.hasFocus() || mCurrentView.isFocused()) {
       mTabWidget.getChildTabViewAt(mCurrentTab).requestFocus();
     }
   }
 }
Example #3
0
  /** 光标移动 到达后 与控件同时放大 */
  private void moveCover(View item) {
    if (cursor == null) {
      return;
    }
    if (!item.isFocused()) {
      return;
    }

    setBorderParams(item);
  }
Example #4
0
  public boolean arrowScroll(int var1) {
    boolean var7 = false;
    View var9 = this.findFocus();
    View var8 = var9;
    if (var9 == this) {
      var8 = null;
    }

    var9 = FocusFinder.getInstance().findNextFocus(this, var8, var1);
    int var4 = this.getMaxScrollAmount();
    if (var9 != null && this.isWithinDeltaOfScreen(var9, var4, this.getHeight())) {
      var9.getDrawingRect(this.mTempRect);
      this.offsetDescendantRectToMyCoords(var9, this.mTempRect);
      this.doScrollY(this.computeScrollDeltaToGetChildRectOnScreen(this.mTempRect));
      var9.requestFocus(var1);
    } else {
      int var2;
      if (var1 == 33 && this.getScrollY() < var4) {
        var2 = this.getScrollY();
      } else {
        var2 = var4;
        if (var1 == 130) {
          var2 = var4;
          if (this.getChildCount() > 0) {
            int var5 = this.getChildAt(0).getBottom();
            int var6 = this.getScrollY() + this.getHeight() - this.getPaddingBottom();
            var2 = var4;
            if (var5 - var6 < var4) {
              var2 = var5 - var6;
            }
          }
        }
      }

      if (var2 == 0) {
        return var7;
      }

      if (var1 != 130) {
        var2 = -var2;
      }

      this.doScrollY(var2);
    }

    if (var8 != null && var8.isFocused() && this.isOffScreen(var8)) {
      var1 = this.getDescendantFocusability();
      this.setDescendantFocusability(131072);
      this.requestFocus();
      this.setDescendantFocusability(var1);
    }

    var7 = true;
    return var7;
  }
  /**
   * Handle scrolling in response to an up or down arrow click.
   *
   * @param direction The direction corresponding to the arrow key that was pressed
   * @return True if we consumed the event, false otherwise
   */
  public boolean arrowScroll(int direction) {

    View currentFocused = findFocus();
    if (currentFocused == this) currentFocused = null;

    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);

    final int maxJump = getMaxScrollAmount();

    if (nextFocused != null && isWithinDeltaOfScreen(nextFocused, maxJump, getHeight())) {
      nextFocused.getDrawingRect(mTempRect);
      offsetDescendantRectToMyCoords(nextFocused, mTempRect);
      int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
      doScrollY(scrollDelta);
      nextFocused.requestFocus(direction);
    } else {
      // no new focus
      int scrollDelta = maxJump;

      if (direction == View.FOCUS_UP && getScrollY() < scrollDelta) {
        scrollDelta = getScrollY();
      } else if (direction == View.FOCUS_DOWN) {
        if (getChildCount() > 0) {
          int daBottom = getChildAt(0).getBottom();

          int screenBottom = getScrollY() + getHeight();

          if (daBottom - screenBottom < maxJump) {
            scrollDelta = daBottom - screenBottom;
          }
        }
      }
      if (scrollDelta == 0) {
        return false;
      }
      doScrollY(direction == View.FOCUS_DOWN ? scrollDelta : -scrollDelta);
    }

    if (currentFocused != null && currentFocused.isFocused() && isOffScreen(currentFocused)) {
      // previously focused item still has focus and is off screen, give
      // it up (take it back to ourselves)
      // (also, need to temporarily force FOCUS_BEFORE_DESCENDANTS so we
      // are
      // sure to
      // get it)
      final int descendantFocusability = getDescendantFocusability(); // save
      setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
      requestFocus();
      setDescendantFocusability(descendantFocusability); // restore
    }
    return true;
  }
Example #6
0
  private void scaleToLarge(View item) {

    if (!item.isFocused()) {
      return;
    }

    animatorSet = new AnimatorSet();
    largeX = ObjectAnimator.ofFloat(item, "ScaleX", 1f, scale);
    ObjectAnimator largeY = ObjectAnimator.ofFloat(item, "ScaleY", 1f, scale);
    ObjectAnimator cursorX = ObjectAnimator.ofFloat(cursor, "ScaleX", 1f, scale);
    ObjectAnimator cursorY = ObjectAnimator.ofFloat(cursor, "ScaleY", 1f, scale);

    animatorSet.setDuration(durationLarge);
    animatorSet.play(largeX).with(largeY).with(cursorX).with(cursorY);
    animatorSet.start();
  }
Example #7
0
 private static String m91a(View view) {
   char c = 'F';
   char c2 = '.';
   StringBuilder stringBuilder = new StringBuilder(128);
   stringBuilder.append(view.getClass().getName());
   stringBuilder.append('{');
   stringBuilder.append(Integer.toHexString(System.identityHashCode(view)));
   stringBuilder.append(' ');
   switch (view.getVisibility()) {
     case 0:
       stringBuilder.append('V');
       break;
     case 4:
       stringBuilder.append('I');
       break;
     case 8:
       stringBuilder.append('G');
       break;
     default:
       stringBuilder.append('.');
       break;
   }
   stringBuilder.append(view.isFocusable() ? 'F' : '.');
   stringBuilder.append(view.isEnabled() ? 'E' : '.');
   stringBuilder.append(view.willNotDraw() ? '.' : 'D');
   stringBuilder.append(view.isHorizontalScrollBarEnabled() ? 'H' : '.');
   stringBuilder.append(view.isVerticalScrollBarEnabled() ? 'V' : '.');
   stringBuilder.append(view.isClickable() ? 'C' : '.');
   stringBuilder.append(view.isLongClickable() ? 'L' : '.');
   stringBuilder.append(' ');
   if (!view.isFocused()) {
     c = '.';
   }
   stringBuilder.append(c);
   stringBuilder.append(view.isSelected() ? 'S' : '.');
   if (view.isPressed()) {
     c2 = 'P';
   }
   stringBuilder.append(c2);
   stringBuilder.append(' ');
   stringBuilder.append(view.getLeft());
   stringBuilder.append(',');
   stringBuilder.append(view.getTop());
   stringBuilder.append('-');
   stringBuilder.append(view.getRight());
   stringBuilder.append(',');
   stringBuilder.append(view.getBottom());
   int id = view.getId();
   if (id != -1) {
     stringBuilder.append(" #");
     stringBuilder.append(Integer.toHexString(id));
     Resources resources = view.getResources();
     if (!(id == 0 || resources == null)) {
       String str;
       switch (-16777216 & id) {
         case 16777216:
           str = "android";
           break;
         case 2130706432:
           str = "app";
           break;
         default:
           try {
             str = resources.getResourcePackageName(id);
             break;
           } catch (NotFoundException e) {
             break;
           }
       }
       String resourceTypeName = resources.getResourceTypeName(id);
       String resourceEntryName = resources.getResourceEntryName(id);
       stringBuilder.append(" ");
       stringBuilder.append(str);
       stringBuilder.append(":");
       stringBuilder.append(resourceTypeName);
       stringBuilder.append("/");
       stringBuilder.append(resourceEntryName);
     }
   }
   stringBuilder.append("}");
   return stringBuilder.toString();
 }
 private static String a(View paramView)
 {
   char c3 = 'F';
   char c2 = '.';
   StringBuilder localStringBuilder = new StringBuilder(128);
   localStringBuilder.append(paramView.getClass().getName());
   localStringBuilder.append('{');
   localStringBuilder.append(Integer.toHexString(System.identityHashCode(paramView)));
   localStringBuilder.append(' ');
   char c1;
   label118:
   label135:
   label152:
   label169:
   label186:
   label203:
   label220:
   label244:
   label261:
   int n;
   Object localObject;
   switch (paramView.getVisibility())
   {
   default: 
     localStringBuilder.append('.');
     if (paramView.isFocusable())
     {
       c1 = 'F';
       localStringBuilder.append(c1);
       if (!paramView.isEnabled()) {
         break label562;
       }
       c1 = 'E';
       localStringBuilder.append(c1);
       if (!paramView.willNotDraw()) {
         break label568;
       }
       c1 = '.';
       localStringBuilder.append(c1);
       if (!paramView.isHorizontalScrollBarEnabled()) {
         break label574;
       }
       c1 = 'H';
       localStringBuilder.append(c1);
       if (!paramView.isVerticalScrollBarEnabled()) {
         break label580;
       }
       c1 = 'V';
       localStringBuilder.append(c1);
       if (!paramView.isClickable()) {
         break label586;
       }
       c1 = 'C';
       localStringBuilder.append(c1);
       if (!paramView.isLongClickable()) {
         break label592;
       }
       c1 = 'L';
       localStringBuilder.append(c1);
       localStringBuilder.append(' ');
       if (!paramView.isFocused()) {
         break label598;
       }
       c1 = c3;
       localStringBuilder.append(c1);
       if (!paramView.isSelected()) {
         break label604;
       }
       c1 = 'S';
       localStringBuilder.append(c1);
       c1 = c2;
       if (paramView.isPressed()) {
         c1 = 'P';
       }
       localStringBuilder.append(c1);
       localStringBuilder.append(' ');
       localStringBuilder.append(paramView.getLeft());
       localStringBuilder.append(',');
       localStringBuilder.append(paramView.getTop());
       localStringBuilder.append('-');
       localStringBuilder.append(paramView.getRight());
       localStringBuilder.append(',');
       localStringBuilder.append(paramView.getBottom());
       n = paramView.getId();
       if (n != -1)
       {
         localStringBuilder.append(" #");
         localStringBuilder.append(Integer.toHexString(n));
         localObject = paramView.getResources();
         if ((n != 0) && (localObject != null)) {
           switch (0xFF000000 & n)
           {
           }
         }
       }
     }
     break;
   }
   for (;;)
   {
     try
     {
       paramView = ((Resources)localObject).getResourcePackageName(n);
       String str = ((Resources)localObject).getResourceTypeName(n);
       localObject = ((Resources)localObject).getResourceEntryName(n);
       localStringBuilder.append(" ");
       localStringBuilder.append(paramView);
       localStringBuilder.append(":");
       localStringBuilder.append(str);
       localStringBuilder.append("/");
       localStringBuilder.append((String)localObject);
     }
     catch (Resources.NotFoundException paramView)
     {
       label562:
       label568:
       label574:
       label580:
       label586:
       label592:
       label598:
       label604:
       continue;
     }
     localStringBuilder.append("}");
     return localStringBuilder.toString();
     localStringBuilder.append('V');
     break;
     localStringBuilder.append('I');
     break;
     localStringBuilder.append('G');
     break;
     c1 = '.';
     break label118;
     c1 = '.';
     break label135;
     c1 = 'D';
     break label152;
     c1 = '.';
     break label169;
     c1 = '.';
     break label186;
     c1 = '.';
     break label203;
     c1 = '.';
     break label220;
     c1 = '.';
     break label244;
     c1 = '.';
     break label261;
     paramView = "app";
     continue;
     paramView = "android";
   }
 }
 @Override
 public void onClick(View v) {
   if (v.isFocused()) {
     showForView(v);
   }
 }