android.view.View#hasWindowFocus ( )源码实例Demo

下面列出了android.view.View#hasWindowFocus ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: AndroidRipper   文件: ViewFetcher.java
/**
 * Returns the most recent view container
 *
 * @param views the views to check
 * @return the most recent view container
 */

private final View getRecentContainer(View[] views) {
	View container = null;
	long drawingTime = 0;
	View view;

	for(int i = 0; i < views.length; i++){
		view = views[i];
		if (view != null && view.isShown() && view.hasWindowFocus() && view.getDrawingTime() > drawingTime) {
			container = view;
			drawingTime = view.getDrawingTime();
		}
	}
	return container;
}
 
private View obtainTargetView() {
	final Activity a = obtainActivity();
	//Log.i(TAG, "obtainTargetView a:"+a);
	if (a == null) return null;

	View v = a.findViewById(android.R.id.content).getRootView();
	//Log.i(TAG, "obtainTargetView vr:"+a);
	if (v == null) return null;
	if (v.hasWindowFocus()) return v; // Quick way

	List<View> lv = getWindowManagerViews();
	for(View vi : lv)
	{
		//Log.i(TAG, "obtainTargetView vi:"+vi+" f:"+vi.hasWindowFocus());
		if (vi.hasWindowFocus()) return vi;
	}

	return v;
}
 
源代码3 项目: 4pdaClient-plus   文件: NewsListFragment.java
@Override
public void onItemClick(@NotNull AdapterView<?> adapterView, @NotNull View v, int position, long id) {
    if(!v.hasWindowFocus()) return;
    try {
        id = ListViewMethodsBridge.getItemId(getActivity(), position, id);
        if (id < 0 || getAdapter().getCount() <= id) return;

        Object o = getAdapter().getItem((int) id);
        if (o == null)
            return;
        final News news = (News) o;
        if (TextUtils.isEmpty(news.getId())) return;
        if(!IntentActivity.tryShowSpecial(news.getUrl()))
            MainActivity.addTab(news.getTitle().toString(), news.getUrl(), NewsFragment.newInstance(news.getUrl()));
        getAdapter().notifyDataSetChanged();

    } catch (Throwable ex) {
        AppLog.e(getActivity(), ex);
    }
}
 
private static View getRecentContainer(View[] views) {
    View container = null;
    long drawingTime = 0;

    for (View view : views) {
        if (view != null && view.isShown() && view.hasWindowFocus() && view.getDrawingTime() > drawingTime) {
            container = view;
            drawingTime = view.getDrawingTime();
        }
    }
    return container;
}
 
源代码5 项目: 4pdaClient-plus   文件: NotesListFragment.java
@Override
public void onItemClick(AdapterView<?> adapterView, View v, int position, long id) {
    if(!v.hasWindowFocus()) return;
    id = ListViewMethodsBridge.getItemId(getActivity(), position, id);
    if (id < 0 || getAdapter().getCount() <= id) return;

    Object o = getAdapter().getItem((int) id);
    if (o == null)
        return;
    final IListItem topic = (IListItem) o;

    if (TextUtils.isEmpty(topic.getId())) return;

    try {
        Note note = NotesTable.getNote(topic.getId().toString());
        if (note != null) {
            if (note.Url!=null) {
                IntentActivity.tryShowUrl((Activity) getContext(), getMHandler(), note.Url, true, false, null);
            }else {
                NoteFragment.showNote(topic.getId().toString());
            }
        }
    } catch (IOException | ParseException e) {
        e.printStackTrace();
    }

}
 
源代码6 项目: 4pdaClient-plus   文件: TopicsListFragment.java
@Override
public void onItemClick(AdapterView<?> adapterView, View v, int position, long id) {
    if (!v.hasWindowFocus()) return;
    try {
        id = org.softeg.slartus.forpdaplus.tabs.ListViewMethodsBridge.getItemId(getActivity(), position, id);
        if (id < 0 || getAdapter().getCount() <= id) return;

        Object o = getAdapter().getItem((int) id);
        if (o == null)
            return;
        final IListItem topic = (IListItem) o;
        if (TextUtils.isEmpty(topic.getId())) return;
        if (tryCreatePost(topic))
            return;
        if (!UserInfoRepository.Companion.getInstance().getLogined()) {
            Toast.makeText(getContext(), "Залогиньтесь для просмотра тем форума!", Toast.LENGTH_LONG).show();
        }
        ActionSelectDialogFragment.INSTANCE.execute(getActivity(),
                getString(R.string.default_action),
                String.format("%s.navigate_action", getListName()),
                new CharSequence[]{getString(R.string.navigate_getfirstpost), getString(R.string.navigate_getlastpost), getString(R.string.navigate_getnewpost), getString(R.string.navigate_last_url)},
                new CharSequence[]{Topic.NAVIGATE_VIEW_FIRST_POST, Topic.NAVIGATE_VIEW_LAST_POST, Topic.NAVIGATE_VIEW_NEW_POST, Topic.NAVIGATE_VIEW_LAST_URL},
                value -> showTopicActivity(topic, TopicUtils.getUrlArgs(topic.getId(), value.toString(), Topic.NAVIGATE_VIEW_FIRST_POST.toString())), getString(R.string.default_action_notify)
        );


    } catch (Throwable ex) {
        AppLog.e(getActivity(), ex);
    }
}
 
/** Waits until the window which contains the provided view has focus. */
public static void waitForWindowFocus(View view) throws InterruptedException, TimeoutException {
  long deadline = SystemClock.uptimeMillis() + UI_ACTION_EFFECT_TIMEOUT_MILLIS;
  while (!view.hasWindowFocus()) {
    long millisTillDeadline = deadline - SystemClock.uptimeMillis();
    if (millisTillDeadline < 0) {
      throw new TimeoutException("Timed out while waiting for window focus");
    }
    Thread.sleep(50);
  }
}
 
源代码8 项目: android_9.0.0_r45   文件: InputMethodManager.java
private static boolean canStartInput(View servedView) {
    // We can start input ether the servedView has window focus
    // or the activity is showing autofill ui.
    return servedView.hasWindowFocus() || isAutofillUIShowing(servedView);
}
 
源代码9 项目: Shield   文件: TopBottomLocationManager.java
private void layoutTopNodes() {

        if (topContainer == null) {
            return;
        }
        ArrayList<View> inScreenTopViews = new ArrayList<>();
        for (int i = 0; i < topContainer.getChildCount(); i++) {
            inScreenTopViews.add(topContainer.getChildAt(i));
        }

        if (currentTopNodeList != null && currentTopNodeList.size() > 0) {
            SparseArray<ArrayList<ShieldDisplayNode>> topBucketLst = sortNodes(currentTopNodeList);

            for (int j = 0; j < topBucketLst.size(); j++) {
                ArrayList<ShieldDisplayNode> bucket = topBucketLst.valueAt(j);
                for (int k = bucket.size() - 1; k >= 0; k--) {
                    ShieldDisplayNode node = bucket.get(k);
                    if (node == null || node.view == null) {
                        continue;
                    }
                    TopBottomNodeInfo info = nodeInfoMap.get(node);
                    inScreenTopViews.remove(node.view);
                    layoutToTopContainer(node, info ,getNodeHeight(node, 0));
                }
            }
        }

        if (!inScreenTopViews.isEmpty()) {
            for (int i = 0; i < inScreenTopViews.size(); i++) {
                topContainer.removeView(inScreenTopViews.get(i));
            }
        }

        boolean topFocus = false;
        for (int i = 0; i < topContainer.getChildCount(); i++) {
            View child = topContainer.getChildAt(i);
            if (child.hasWindowFocus() || child.hasFocus()) {
                topFocus = true;
                break;
            }
        }
        if (!topFocus) {
            topContainer.clearFocus();
        }
    }
 
private void triggerDelayedOnCreateInputConnection(final View view) {
    if (DEBUG_LOGS) Log.i(TAG, "triggerDelayedOnCreateInputConnection");
    // Prevent infinite loop when View methods trigger onCreateInputConnection
    // on some OEM phones. (crbug.com/636197)
    if (mReentrantTriggering) return;

    // We need to check this before creating invalidator.
    if (!view.hasFocus()) return;

    mCheckInvalidator = new CheckInvalidator();

    if (!view.hasWindowFocus()) mCheckInvalidator.invalidate();

    // We cannot reuse the existing proxy view, if any, due to crbug.com/664402.
    mProxyView = createProxyView(getHandler(), view);

    mReentrantTriggering = true;
    // This does not affect view focus of the real views.
    mProxyView.requestFocus();
    mReentrantTriggering = false;

    view.getHandler().post(new Runnable() {
        @Override
        public void run() {
            // This is a hack to make InputMethodManager believe that the proxy view
            // now has a focus. As a result, InputMethodManager will think that mProxyView
            // is focused, and will call getHandler() of the view when creating input
            // connection.

            // Step 1: Set mProxyView as InputMethodManager#mNextServedView.
            // This does not affect the real window focus.
            mProxyView.onWindowFocusChanged(true);

            // Step 2: Have InputMethodManager focus in on mNextServedView.
            // As a result, IMM will call onCreateInputConnection() on mProxyView on the same
            // thread as mProxyView.getHandler(). It will also call subsequent InputConnection
            // methods on this IME thread.
            mInputMethodManagerWrapper.isActive(view);

            // Step 3: Check that the above hack worked.
            // Do not check until activation finishes inside InputMethodManager (on IME thread).
            getHandler().post(new Runnable() {
                @Override
                public void run() {
                    postCheckRegisterResultOnUiThread(view, mCheckInvalidator,
                            CHECK_REGISTER_RETRY);
                }
            });
        }
    });
}
 
源代码11 项目: android-test   文件: RootMatchers.java
@Override
public boolean matchesSafely(View view) {
  return view.hasWindowFocus();
}
 
 方法所在类
 同类方法