Example #1
0
    void show(int offx, int offy) {
      int textHeight = chooseSize(window, inputView, text, textView);
      offy -= textView.getPaddingTop() + textHeight;
      if (inputView.getVisibility() == View.VISIBLE
          && inputView.getWindowVisibility() == View.VISIBLE) {
        try {
          if ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) offy -= window.getHeight();
          if ((gravity & Gravity.RIGHT) == Gravity.RIGHT) offx -= window.getWidth();
          textView.setOnTouchListener(
              new View.OnTouchListener() {
                public boolean onTouch(View view, MotionEvent me) {

                  boolean ret = !mEnableKeyTouch;
                  switch (me.getAction()) {
                    case MotionEvent.ACTION_UP:
                      if (mBubbleIndex >= mBubbles.size()) {
                        mInputView.setOnTouchListener(null);
                      } else {
                        TutorialJAJP.this.next();
                      }
                      break;
                    default:
                      break;
                  }
                  return ret;
                }
              });
          window.showAtLocation(inputView, Gravity.NO_GRAVITY, x + offx, y + offy);
        } catch (Exception e) {
        }
      }
    }
  /**
   * Computes whether the specified {@link android.graphics.Rect} intersects with the visible
   * portion of its parent {@link android.view.View}. Modifies {@code localRect} to contain only the
   * visible portion.
   *
   * @param localRect A rectangle in local (parent) coordinates.
   * @return Whether the specified {@link android.graphics.Rect} is visible on the screen.
   */
  private boolean intersectVisibleToUser(Rect localRect) {
    // Missing or empty bounds mean this view is not visible.
    if ((localRect == null) || localRect.isEmpty()) {
      return false;
    }

    // Attached to invisible window means this view is not visible.
    if (mParentView.getWindowVisibility() != View.VISIBLE) {
      return false;
    }

    // An invisible predecessor or one with alpha zero means
    // that this view is not visible to the user.
    Object current = this;
    while (current instanceof View) {
      final View view = (View) current;
      // We have attach info so this view is attached and there is no
      // need to check whether we reach to ViewRootImpl on the way up.
      if ((view.getAlpha() <= 0) || (view.getVisibility() != View.VISIBLE)) {
        return false;
      }
      current = view.getParent();
    }

    // If no portion of the parent is visible, this view is not visible.
    if (!mParentView.getLocalVisibleRect(mTempVisibleRect)) {
      return false;
    }

    // Check if the view intersects the visible portion of the parent.
    return localRect.intersect(mTempVisibleRect);
  }
Example #3
0
    @TargetApi(Build.VERSION_CODES.KITKAT)
    private void clearInputMethodManagerLeak() {
      try {
        Object lock = mHField.get(inputMethodManager);
        // This is highly dependent on the InputMethodManager implementation.
        synchronized (lock) {
          View servedView = (View) mServedViewField.get(inputMethodManager);
          if (servedView != null) {

            boolean servedViewAttached = servedView.getWindowVisibility() != View.GONE;

            if (servedViewAttached) {
              // The view held by the IMM was replaced without a global focus change. Let's make
              // sure we get notified when that view detaches.

              // Avoid double registration.
              servedView.removeOnAttachStateChangeListener(this);
              servedView.addOnAttachStateChangeListener(this);
            } else {
              // servedView is not attached. InputMethodManager is being stupid!
              Activity activity = extractActivity(servedView.getContext());
              if (activity == null || activity.getWindow() == null) {
                // Unlikely case. Let's finish the input anyways.
                finishInputLockedMethod.invoke(inputMethodManager);
              } else {
                View decorView = activity.getWindow().peekDecorView();
                boolean windowAttached = decorView.getWindowVisibility() != View.GONE;
                if (!windowAttached) {
                  finishInputLockedMethod.invoke(inputMethodManager);
                } else {
                  decorView.requestFocusFromTouch();
                }
              }
            }
          }
        }
      } catch (IllegalAccessException | InvocationTargetException unexpected) {
        Log.e("IMMLeaks", "Unexpected reflection exception", unexpected);
      }
    }
  private boolean intersectVisibleToUser(Rect rect) {
    if (rect == null || rect.isEmpty()) {
      return false;
    }
    if (mView.getWindowVisibility() != 0) {
      return false;
    }
    Object obj;
    for (obj = mView.getParent(); obj instanceof View; obj = ((View) (obj)).getParent()) {
      obj = (View) obj;
      if (ViewCompat.getAlpha(((View) (obj))) <= 0.0F || ((View) (obj)).getVisibility() != 0) {
        return false;
      }
    }

    if (obj == null) {
      return false;
    }
    if (!mView.getLocalVisibleRect(mTempVisibleRect)) {
      return false;
    } else {
      return rect.intersect(mTempVisibleRect);
    }
  }