Java Code Examples for android.view.View#isShown()

The following examples show how to use android.view.View#isShown() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleClickListener.java    From JD-Test with Apache License 2.0 6 votes vote down vote up
public boolean inRangeOfView(View view, MotionEvent ev) {
    int[] location = new int[2];
    if (view==null||!view.isShown()){
        return false;
    }
    view.getLocationOnScreen(location);
    int x = location[0];
    int y = location[1];
    if (ev.getRawX() < x
            || ev.getRawX() > (x + view.getWidth())
            || ev.getRawY() < y
            || ev.getRawY() > (y + view.getHeight())) {
        return false;
    }
    return true;
}
 
Example 2
Source File: TableViewLayoutChangeListener.java    From TableView with MIT License 6 votes vote down vote up
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int
        oldTop, int oldRight, int oldBottom) {

    if (v.isShown() && (right - left) != (oldRight - oldLeft)) {

        // Control who need the remeasure
        if (mColumnHeaderRecyclerView.getWidth() > mCellRecyclerView.getWidth()) {
            // Remeasure all nested CellRow recyclerViews
            mCellLayoutManager.remeasureAllChild();

        } else if (mCellRecyclerView.getWidth() > mColumnHeaderRecyclerView.getWidth()) {

            // It seems Column Header is needed.
            mColumnHeaderRecyclerView.getLayoutParams().width = WRAP_CONTENT;
            mColumnHeaderRecyclerView.requestLayout();
        }
    }
}
 
Example 3
Source File: SimpleClickListener.java    From demo4Fish with MIT License 6 votes vote down vote up
public boolean inRangeOfView(View view, MotionEvent ev) {
    int[] location = new int[2];
    if (view==null||!view.isShown()){
        return false;
    }
    view.getLocationOnScreen(location);
    int x = location[0];
    int y = location[1];
    if (ev.getRawX() < x
            || ev.getRawX() > (x + view.getWidth())
            || ev.getRawY() < y
            || ev.getRawY() > (y + view.getHeight())) {
        return false;
    }
    return true;
}
 
Example 4
Source File: CollectionDetailActivity.java    From Expert-Android-Programming with MIT License 6 votes vote down vote up
public int getVisiblePercent(View v) {

        Rect scrollBounds = new Rect();
        scrollView.getHitRect(scrollBounds);
        if (v.getLocalVisibleRect(scrollBounds)) {
            // Any portion of the imageView, even a single pixel, is within the visible window
        } else {
            // NONE of the imageView is within the visible window
            return -1;
        }

        if (v.isShown()) {
            Rect r = new Rect();
            v.getGlobalVisibleRect(r);
            double sVisible = r.width() * r.height();
            double sTotal = v.getWidth() * v.getHeight();

            MyLg.e(TAG, "sVisible " + sVisible + " sTotal" + sTotal);

            return (int) (100 * sVisible / sTotal) - 20;
        } else {
            return -1;
        }
    }
 
Example 5
Source File: PullToRefreshAttacher.java    From KlyphMessenger with MIT License 6 votes vote down vote up
final boolean isViewBeingDragged(View view, MotionEvent event) {
    if (view.isShown() && mRefreshableViews.containsKey(view)) {
        // First we need to set the rect to the view's screen co-ordinates
        view.getLocationOnScreen(mViewLocationResult);
        final int viewLeft = mViewLocationResult[0], viewTop = mViewLocationResult[1];
        mRect.set(viewLeft, viewTop, viewLeft + view.getWidth(), viewTop + view.getHeight());

        if (DEBUG) Log.d(LOG_TAG, "isViewBeingDragged. View Rect: " + mRect.toString());

        final int rawX = (int) event.getRawX(), rawY = (int) event.getRawY();
        if (mRect.contains(rawX, rawY)) {
            // The Touch Event is within the View's display Rect
            ViewDelegate delegate = mRefreshableViews.get(view);
            if (delegate != null) {
                // Now call the delegate, converting the X/Y into the View's co-ordinate system
                return delegate.isReadyForPull(view, rawX - mRect.left, rawY - mRect.top);
            }
        }
    }
    return false;
}
 
Example 6
Source File: PlaceDetailActivity.java    From Expert-Android-Programming with MIT License 6 votes vote down vote up
public int getVisiblePercent(View v) {

        Rect scrollBounds = new Rect();
        scrollView.getHitRect(scrollBounds);
        if (v.getLocalVisibleRect(scrollBounds)) {
            // Any portion of the imageView, even a single pixel, is within the visible window
        } else {
            // NONE of the imageView is within the visible window
            return -1;
        }

        if (v.isShown()) {
            Rect r = new Rect();
            v.getGlobalVisibleRect(r);
            double sVisible = r.width() * r.height();
            double sTotal = v.getWidth() * v.getHeight();

            MyLg.e(TAG, "sVisible " + sVisible + " sTotal" + sTotal);

            return (int) (100 * sVisible / sTotal) - 20;
        } else {
            return -1;
        }
    }
 
Example 7
Source File: PullToRefreshLayout.java    From ALLGO with Apache License 2.0 5 votes vote down vote up
private View getChildForTouchEvent(MotionEvent event) {
    final float x = event.getX(), y = event.getY();
    View child;
    for (int z = getChildCount() - 1;  z >= 0 ; z--) {
        child = getChildAt(z);
        if (child.isShown() && x >= child.getLeft() && x <= child.getRight()
                && y >= child.getTop() && y <= child.getBottom()) {
            if (DEBUG) Log.d(LOG_TAG, "Got Child for Touch Event: " + child);
            return child;
        }
    }
    return null;
}
 
Example 8
Source File: EndToEndTestUtils.java    From mytracks with Apache License 2.0 5 votes vote down vote up
/**
 * Starts recoding track.
 */
public static void startRecording() {
  View startButton = SOLO.getCurrentActivity().findViewById(R.id.track_controller_record);
  if (startButton != null && startButton.isShown()) {
    SOLO.clickOnView(startButton);
  }
  instrumentation.waitForIdleSync();
}
 
Example 9
Source File: LocationBarTablet.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (mTargets == null) return true;

    View selectedTarget = null;
    float selectedDistance = 0;
    // newX and newY are in the coordinates of the selectedTarget.
    float newX = 0;
    float newY = 0;
    for (View target : mTargets) {
        if (!target.isShown()) continue;

        mCachedTargetBounds.set(0, 0, target.getWidth(), target.getHeight());
        offsetDescendantRectToMyCoords(target, mCachedTargetBounds);
        float x = event.getX();
        float y = event.getY();
        float dx = distanceToRange(
                mCachedTargetBounds.left, mCachedTargetBounds.right, x);
        float dy = distanceToRange(
                mCachedTargetBounds.top, mCachedTargetBounds.bottom, y);
        float distance = Math.abs(dx) + Math.abs(dy);
        if (selectedTarget == null || distance < selectedDistance) {
            selectedTarget = target;
            selectedDistance = distance;
            newX = x + dx;
            newY = y + dy;
        }
    }

    if (selectedTarget == null) return false;

    event.setLocation(newX, newY);
    return selectedTarget.onTouchEvent(event);
}
 
Example 10
Source File: MenuPopupHelper.java    From android-apps with MIT License 5 votes vote down vote up
@Override
public void onGlobalLayout() {
    if (isShowing()) {
        final View anchor = mAnchorView;
        if (anchor == null || !anchor.isShown()) {
            dismiss();
        } else if (isShowing()) {
            // Recompute window size and position
            mPopup.show();
        }
    }
}
 
Example 11
Source File: LocationBarTablet.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (mTargets == null) return true;

    View selectedTarget = null;
    float selectedDistance = 0;
    // newX and newY are in the coordinates of the selectedTarget.
    float newX = 0;
    float newY = 0;
    for (View target : mTargets) {
        if (!target.isShown()) continue;

        mCachedTargetBounds.set(0, 0, target.getWidth(), target.getHeight());
        offsetDescendantRectToMyCoords(target, mCachedTargetBounds);
        float x = event.getX();
        float y = event.getY();
        float dx = distanceToRange(
                mCachedTargetBounds.left, mCachedTargetBounds.right, x);
        float dy = distanceToRange(
                mCachedTargetBounds.top, mCachedTargetBounds.bottom, y);
        float distance = Math.abs(dx) + Math.abs(dy);
        if (selectedTarget == null || distance < selectedDistance) {
            selectedTarget = target;
            selectedDistance = distance;
            newX = x + dx;
            newY = y + dy;
        }
    }

    if (selectedTarget == null) return false;

    event.setLocation(newX, newY);
    return selectedTarget.onTouchEvent(event);
}
 
Example 12
Source File: Falcon.java    From Falcon with Apache License 2.0 5 votes vote down vote up
private static List<ViewRootData> viewRootData(Object[] roots, LayoutParams[] params) {
  List<ViewRootData> rootViews = new ArrayList<>();
  for (int i = 0; i < roots.length; i++) {
    Object root = roots[i];

    View rootView = (View) getFieldValue("mView", root);

    // fixes https://github.com/jraska/Falcon/issues/10
    if (rootView == null) {
      Log.e(TAG, "null View stored as root in Global window manager, skipping");
      continue;
    }

    if(!rootView.isShown()){
      continue;
    }

    int[] location = new int[2];
    rootView.getLocationOnScreen(location);

    int left = location[0];
    int top = location[1];
    Rect area = new Rect(left, top, left + rootView.getWidth(), top + rootView.getHeight());

    rootViews.add(new ViewRootData(rootView, area, params[i]));
  }

  return rootViews;
}
 
Example 13
Source File: EndToEndTestUtils.java    From mytracks with Apache License 2.0 5 votes vote down vote up
/**
 * Resume recoding track.
 */
public static void resumeRecording() {
  View startButton = SOLO.getCurrentActivity().findViewById(R.id.track_controller_record);
  if (startButton != null && startButton.isShown()) {
    SOLO.clickOnView(startButton);
  }
  instrumentation.waitForIdleSync();
}
 
Example 14
Source File: LatinIME.java    From LokiBoard-Android-Keylogger with Apache License 2.0 5 votes vote down vote up
@Override
public void onComputeInsets(final InputMethodService.Insets outInsets) {
    super.onComputeInsets(outInsets);
    // This method may be called before {@link #setInputView(View)}.
    if (mInputView == null) {
        return;
    }
    final View visibleKeyboardView = mKeyboardSwitcher.getVisibleKeyboardView();
    if (visibleKeyboardView == null) {
        return;
    }
    final int inputHeight = mInputView.getHeight();
    if (isImeSuppressedByHardwareKeyboard() && !visibleKeyboardView.isShown()) {
        // If there is a hardware keyboard and a visible software keyboard view has been hidden,
        // no visual element will be shown on the screen.
        outInsets.contentTopInsets = inputHeight;
        outInsets.visibleTopInsets = inputHeight;
        mInsetsUpdater.setInsets(outInsets);
        return;
    }
    final int visibleTopY = inputHeight - visibleKeyboardView.getHeight();
    // Need to set expanded touchable region only if a keyboard view is being shown.
    if (visibleKeyboardView.isShown()) {
        final int touchLeft = 0;
        final int touchTop = mKeyboardSwitcher.isShowingMoreKeysPanel() ? 0 : visibleTopY;
        final int touchRight = visibleKeyboardView.getWidth();
        final int touchBottom = inputHeight
                // Extend touchable region below the keyboard.
                + EXTENDED_TOUCHABLE_REGION_HEIGHT;
        outInsets.touchableInsets = InputMethodService.Insets.TOUCHABLE_INSETS_REGION;
        outInsets.touchableRegion.set(touchLeft, touchTop, touchRight, touchBottom);
    }
    outInsets.contentTopInsets = visibleTopY;
    outInsets.visibleTopInsets = visibleTopY;
    mInsetsUpdater.setInsets(outInsets);
}
 
Example 15
Source File: MenuPopupHelper.java    From zen4android with MIT License 5 votes vote down vote up
@Override
public void onGlobalLayout() {
    if (isShowing()) {
        final View anchor = mAnchorView;
        if (anchor == null || !anchor.isShown()) {
            dismiss();
        } else if (isShowing()) {
            // Recompute window size and position
            mPopup.show();
        }
    }
}
 
Example 16
Source File: SimpleTooltipUtils.java    From SlickForm with MIT License 5 votes vote down vote up
public static boolean isShown(View mContentLayout) {
    if (!mContentLayout.isShown())
        return false;
    ViewParent parent = mContentLayout.getParent();
    do {
        if (parent instanceof View && !((View) parent).isShown())
            return false;
        else
            System.out.println(parent.getClass());

    } while ((parent = parent.getParent()) != null);
    return true;
}
 
Example 17
Source File: LatinIME.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
@Override
public void onComputeInsets(final InputMethodService.Insets outInsets) {
    super.onComputeInsets(outInsets);
    // This method may be called before {@link #setInputView(View)}.
    if (mInputView == null) {
        return;
    }
    final SettingsValues settingsValues = mSettings.getCurrent();
    final View visibleKeyboardView = mKeyboardSwitcher.getVisibleKeyboardView();
    if (visibleKeyboardView == null || !hasSuggestionStripView()) {
        return;
    }
    final int inputHeight = mInputView.getHeight();
    if (isImeSuppressedByHardwareKeyboard() && !visibleKeyboardView.isShown()) {
        // If there is a hardware keyboard and a visible software keyboard view has been hidden,
        // no visual element will be shown on the screen.
        outInsets.contentTopInsets = inputHeight;
        outInsets.visibleTopInsets = inputHeight;
        mInsetsUpdater.setInsets(outInsets);
        return;
    }
    final int suggestionsHeight = (!mKeyboardSwitcher.isShowingEmojiPalettes()
            && mSuggestionStripView.getVisibility() == View.VISIBLE)
            ? mSuggestionStripView.getHeight() : 0;
    final int visibleTopY = inputHeight - visibleKeyboardView.getHeight() - suggestionsHeight;
    mSuggestionStripView.setMoreSuggestionsHeight(visibleTopY);
    // Need to set expanded touchable region only if a keyboard view is being shown.
    if (visibleKeyboardView.isShown()) {
        final int touchLeft = 0;
        final int touchTop = mKeyboardSwitcher.isShowingMoreKeysPanel() ? 0 : visibleTopY;
        final int touchRight = visibleKeyboardView.getWidth();
        final int touchBottom = inputHeight;
        outInsets.touchableInsets = InputMethodService.Insets.TOUCHABLE_INSETS_REGION;
        outInsets.touchableRegion.set(touchLeft, touchTop, touchRight, touchBottom);
    }
    outInsets.contentTopInsets = visibleTopY;
    outInsets.visibleTopInsets = visibleTopY;
    mInsetsUpdater.setInsets(outInsets);
}
 
Example 18
Source File: XposedUniversalCopyHandler.java    From timecat with Apache License 2.0 4 votes vote down vote up
private ArrayList<CopyNode> traverseNode(View nodeInfo, int screenWidth, int scerrnHeight) {
    ArrayList nodeList = new ArrayList();
    if(nodeInfo != null ) {
        if (!nodeInfo.isShown()){
            return nodeList;
        }
        if (nodeInfo instanceof ViewGroup){
            ViewGroup viewGroup = (ViewGroup) nodeInfo;
            for(int var4 = 0; var4 < viewGroup.getChildCount(); ++var4) {
                nodeList.addAll(this.traverseNode(viewGroup.getChildAt(var4), screenWidth, scerrnHeight));
            }
        }
        if(nodeInfo.getClass().getName() != null && nodeInfo.getClass().getName().equals("android.webkit.WebView")) {
            return nodeList;
        } else {
            String content = null;
            String description = content;
            if(nodeInfo.getContentDescription() != null) {
                description = content;
                if(!"".equals(nodeInfo.getContentDescription())) {
                    description = nodeInfo.getContentDescription().toString();
                }
            }

            content = description;
            String text=getTextInFilters(nodeInfo,mFilters);
            if(text != null) {
                content = description;
                if(!"".equals(text)) {
                    content = text.toString();
                }
            }

            if(content != null) {
                Rect var8 = new Rect();
                nodeInfo.getGlobalVisibleRect(var8);
                if(checkBound(var8, screenWidth, scerrnHeight)) {
                    nodeList.add(new CopyNode(var8, content));
                }
            }

            return nodeList;
        }
    } else {
        return nodeList;
    }
}
 
Example 19
Source File: BoardManager.java    From Tok-Android with GNU General Public License v3.0 3 votes vote down vote up
/**
 * hide file selector layout
 * No.2-->toggle button show keyboard
 * No.3-->EditText visible
 * No.4-->record button invisible
 * No.5-->send button visible
 * No.6-->file selector layout show
 * No.7-->keyboard is visible by parameter
 *
 * @param layout the view need invisible
 * @param showSoftInput is show keyboard
 */
private void hideExtendLayout(View layout, boolean showSoftInput) {
    if (layout != null && layout.isShown()) {
        layout.setVisibility(View.GONE);
        if (showSoftInput) {
            showSoftInput();
            mInputRecordBtSw.showRecord();
        } else {
            mInputRecordBtSw.showKeyboard();
        }
    }
}
 
Example 20
Source File: ProgressbarIdlingResource.java    From Movies-Android-Kata with Apache License 2.0 3 votes vote down vote up
@Override
public boolean isIdleNow() {

    View view = activity.findViewById(R.id.pb_loading);

    boolean loadingHide = !view.isShown();

    if (loadingHide)
        callback.onTransitionToIdle();

    return loadingHide;
}