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

The following are Jave code examples for showing how to use isShown() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Expert-Android-Programming   File: PlaceDetailActivity.java   Source Code and License Vote up 8 votes
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 2
Project: Expert-Android-Programming   File: CollectionDetailActivity.java   Source Code and License Vote up 7 votes
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 3
Project: SetupWizardLibCompat   File: StickyHeaderScrollView.java   Source Code and License Vote up 7 votes
private void updateStickyHeaderPosition() {
    // Note: for pre-Honeycomb the header will not be moved, so this ScrollView essentially
    // behaves like a normal BottomScrollView.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        if (mSticky != null) {
            // The view to draw when sticking to the top
            final View drawTarget = mStickyContainer != null ? mStickyContainer : mSticky;
            // The offset to draw the view at when sticky
            final int drawOffset = mStickyContainer != null ? mSticky.getTop() : 0;
            // Position of the draw target, relative to the outside of the scrollView
            final int drawTop = drawTarget.getTop() - getScrollY();
            if (drawTop + drawOffset < mStatusBarInset || !drawTarget.isShown()) {
                // ScrollView translates the whole canvas so we have to compensate for that
                drawTarget.setTranslationY(getScrollY() - drawOffset);
            } else {
                drawTarget.setTranslationY(0);
            }
        }
    }
}
 
Example 4
Project: chromium-for-android-56-debug-video   File: TabWebContentsDelegateAndroid.java   Source Code and License Vote up 7 votes
@Override
public boolean takeFocus(boolean reverse) {
    Activity activity = mTab.getActivity();
    if (activity == null) return false;
    if (reverse) {
        View menuButton = activity.findViewById(R.id.menu_button);
        if (menuButton == null || !menuButton.isShown()) {
            menuButton = activity.findViewById(R.id.document_menu_button);
        }
        if (menuButton != null && menuButton.isShown()) {
            return menuButton.requestFocus();
        }

        View tabSwitcherButton = activity.findViewById(R.id.tab_switcher_button);
        if (tabSwitcherButton != null && tabSwitcherButton.isShown()) {
            return tabSwitcherButton.requestFocus();
        }
    } else {
        View urlBar = activity.findViewById(R.id.url_bar);
        if (urlBar != null) return urlBar.requestFocus();
    }
    return false;
}
 
Example 5
Project: cwac-crossport   File: AppBarLayout.java   Source Code and License Vote up 7 votes
@Override
boolean canDragView(AppBarLayout view) {
  if (mOnDragCallback != null) {
    // If there is a drag callback set, it's in control
    return mOnDragCallback.canDrag(view);
  }

  // Else we'll use the default behaviour of seeing if it can scroll down
  if (mLastNestedScrollingChildRef != null) {
    // If we have a reference to a scrolling view, check it
    final View scrollingView = mLastNestedScrollingChildRef.get();
            return scrollingView != null && scrollingView.isShown()
                    && !scrollingView.canScrollVertically(-1);
  } else {
    // Otherwise we assume that the scrolling view hasn't been scrolled and can drag.
    return true;
  }
}
 
Example 6
Project: SetupWizardLibCompat   File: StickyHeaderListView.java   Source Code and License Vote up 7 votes
@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    if (mSticky != null) {
        final int saveCount = canvas.save();
        // The view to draw when sticking to the top
        final View drawTarget = mStickyContainer != null ? mStickyContainer : mSticky;
        // The offset to draw the view at when sticky
        final int drawOffset = mStickyContainer != null ? mSticky.getTop() : 0;
        // Position of the draw target, relative to the outside of the scrollView
        final int drawTop = drawTarget.getTop();
        if (drawTop + drawOffset < mStatusBarInset || !drawTarget.isShown()) {
            // ListView does not translate the canvas, so we can simply draw at the top
            mStickyRect.set(0, -drawOffset + mStatusBarInset, drawTarget.getWidth(),
                    drawTarget.getHeight() - drawOffset + mStatusBarInset);
            canvas.translate(0, mStickyRect.top);
            canvas.clipRect(0, 0, drawTarget.getWidth(), drawTarget.getHeight());
            drawTarget.draw(canvas);
        } else {
            mStickyRect.setEmpty();
        }
        canvas.restoreToCount(saveCount);
    }
}
 
Example 7
Project: JD-Test   File: SimpleClickListener.java   Source Code and License Vote up 7 votes
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 8
Project: recyclerview-android   File: ClickableViewFinder.java   Source Code and License Vote up 7 votes
@Nullable
private View findViewAt(@NonNull final View view, final float x, final float y) {
    if (!view.isShown() || !view.isEnabled() || !isViewAt(view, x, y)) {
        return null;
    }

    if (view instanceof ViewGroup) {
        final float transformedX = x - view.getLeft() - ViewCompat.getTranslationX(view);
        final float transformedY = y - view.getTop() - ViewCompat.getTranslationY(view);

        final ViewGroup viewGroup = (ViewGroup) view;
        final int childCount = viewGroup.getChildCount();
        for (int i = childCount - 1; i >= 0; i--) {
            final View child = viewGroup.getChildAt(i);
            final View foundView = findViewAt(child, transformedX, transformedY);
            if (foundView != null) {
                return foundView;
            }
        }
    }

    return view;
}
 
Example 9
Project: LiveNotes   File: SeeScoreView.java   Source Code and License Vote up 6 votes
private void scrollToBar(int barIndex, int autoScrollAnimationTime) {
    ViewParent parentView = getParent();
    if (parentView instanceof ScrollView) {
        final ScrollView parentScrollView = (ScrollView) parentView;
        for (View view : views) {
            if (view instanceof SystemView
                    && view.isShown()) {
                SystemView systemView = (SystemView) view;
                if (systemView.containsBar(barIndex)) {
                    int scroll_max = getBottom() - parentScrollView.getHeight();
                    int scroll_min = 0;
                    float windowHeight = parentScrollView.getHeight();
                    float windowPlayingCentre = kWindowPlayingCentreFractionFromTop * windowHeight;
                    float sysFrac = systemView.fractionalScroll(barIndex);
                    float playingCentre = view.getTop() + view.getHeight() * sysFrac;
                    float scroll_y = playingCentre - windowPlayingCentre;

                    if (scroll_y < scroll_min)
                        scroll_y = scroll_min;
                    else if (scroll_y > scroll_max)
                        scroll_y = scroll_max;
                    slowSmoothScrollTo(parentScrollView, (int) scroll_y, autoScrollAnimationTime);
                }
            }
        }
    }
}
 
Example 10
Project: boohee_v5.6   File: MenuPopupHelper.java   Source Code and License Vote up 6 votes
public void onGlobalLayout() {
    if (isShowing()) {
        View anchor = this.mAnchorView;
        if (anchor == null || !anchor.isShown()) {
            dismiss();
        } else if (isShowing()) {
            this.mPopup.show();
        }
    }
}
 
Example 11
Project: LiveNotes   File: SeeScoreView.java   Source Code and License Vote up 6 votes
/**
 * set the vertical line cursor at a given bar with a given xpos (from the system left)
 * @param barIndex the (0-based) bar index
 * @param xpos the x coordinate from the system left
 * @param autoScrollAnimationTime a hint for the scroll time in ms
 * @return true if it succeeded
 */
public boolean setCursorAtBar(int barIndex, float xpos, int autoScrollAnimationTime) {
    boolean rval = false;
    for (View view : views) {
        if (view instanceof SystemView
                && view.isShown()) {
            SystemView systemView = (SystemView) view;
            if (systemView.setCursorAtBar(barIndex, xpos)) {
                scrollToBar(barIndex, autoScrollAnimationTime);
            }
        }
    }
    return rval;
}
 
Example 12
Project: LiveNotes   File: SeeScoreView.java   Source Code and License Vote up 6 votes
/**
 * called during active pinching. Do quick rescale of display without relayout
 * Relayout happens on completion of gesture
 * 
 * @param zoom the current magnification based on the finger spacing compared
 * to the spacing at the start of the pinch
 */
private void zooming(final float zoom)
{
	float mag;
	if (magnification < kMinMag)
		magnification = kMinMag; // ensure no div-by-zero
	if (zoom * magnification < kMinMag)
		mag = kMinMag / magnification;
	else if (zoom * magnification > kMaxMag)
		mag = kMaxMag / magnification;
	else if (Math.abs(zoom * magnification - 1.0) < 0.05) // make easy to set 1.0
		mag = 1.0F / magnification;
	else
		mag = zoom;
	
	for (View view : views)
	{
		if (view instanceof SystemView
			&& view.isShown())
		{
			Rect r = new Rect();
			boolean vis = view.getGlobalVisibleRect (r);
			if (vis)
			{
				SystemView sv = (SystemView)view;
				sv.zooming(mag);
			}
		}
	}
	zoomNotify.zoom(zoom * magnification);
}
 
Example 13
Project: LiveNotes   File: SeeScoreView.java   Source Code and License Vote up 6 votes
void colourItem(int partIndex, int barIndex, int item_h, RenderItem.Colour col)
{
	for (View view : views) {
		if (view instanceof SystemView
			&& view.isShown()) {
			SystemView systemView = (SystemView) view;
			if (systemView.containsBar(barIndex))
			{
				systemView.colourItem(partIndex, barIndex, item_h, col);
				return;
			}
		}
	}
}
 
Example 14
Project: LiveNotes   File: SeeScoreView.java   Source Code and License Vote up 6 votes
public void clearAllColouring()
{
	for (View view : views) {
		if (view instanceof SystemView
				&& view.isShown()) {
			SystemView systemView = (SystemView) view;
			systemView.clearAllColouring();
		}
	}
}
 
Example 15
Project: boohee_v5.6   File: AppBarLayout.java   Source Code and License Vote up 6 votes
boolean canDragView(AppBarLayout view) {
    if (this.mOnDragCallback != null) {
        return this.mOnDragCallback.canDrag(view);
    }
    if (this.mLastNestedScrollingChildRef == null) {
        return true;
    }
    View scrollingView = (View) this.mLastNestedScrollingChildRef.get();
    if (scrollingView == null || !scrollingView.isShown() || ViewCompat.canScrollVertically(scrollingView, -1)) {
        return false;
    }
    return true;
}
 
Example 16
Project: simple-keyboard   File: LatinIME.java   Source Code and License Vote up 6 votes
@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 17
Project: chromium-for-android-56-debug-video   File: LocationBarTablet.java   Source Code and License Vote up 6 votes
@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 18
Project: GuardianReader   File: WaitForViewVisibleIdlingResource.java   Source Code and License Vote up 5 votes
@Override
public boolean isIdleNow() {
  View view = activity.findViewById(viewId);
  return view.isShown();
}
 
Example 19
Project: AOSP-Kayboard-7.1.2   File: LatinIME.java   Source Code and License Vote up 5 votes
@Override
public void onComputeInsets(final 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
                // Extend touchable region below the keyboard.
                + EXTENDED_TOUCHABLE_REGION_HEIGHT;
        outInsets.touchableInsets = Insets.TOUCHABLE_INSETS_REGION;
        outInsets.touchableRegion.set(touchLeft, touchTop, touchRight, touchBottom);
    }
    outInsets.contentTopInsets = visibleTopY;
    outInsets.visibleTopInsets = visibleTopY;
    mInsetsUpdater.setInsets(outInsets);
}
 
Example 20
Project: Bigbang   File: XposedUniversalCopyHandler.java   Source Code and License Vote up 5 votes
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;
    }
}