下面列出了android.view.View#isShown ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
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;
}
}
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;
}
}
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;
}
@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();
}
}
}
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;
}
@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);
}
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;
}
@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();
}
}
}
@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);
}
/**
* 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();
}
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;
}
@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);
}
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;
}
@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();
}
}
}
@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);
}
/**
* 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();
}
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;
}
}
/**
* 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();
}
}
}
@Override
public boolean isIdleNow() {
View view = activity.findViewById(R.id.pb_loading);
boolean loadingHide = !view.isShown();
if (loadingHide)
callback.onTransitionToIdle();
return loadingHide;
}