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

The following examples show how to use android.view.View#hasWindowFocus() . 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: ViewFetcher.java    From AndroidRipper with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: InAppInputManager.java    From CatVision-io-SDK-Android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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;
}
 
Example 3
Source File: NewsListFragment.java    From 4pdaClient-plus with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 4
Source File: EspScreenshotToolPreJellyBeanMr2.java    From espresso-macchiato with MIT License 5 votes vote down vote up
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;
}
 
Example 5
Source File: NotesListFragment.java    From 4pdaClient-plus with Apache License 2.0 5 votes vote down vote up
@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();
    }

}
 
Example 6
Source File: TopicsListFragment.java    From 4pdaClient-plus with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 7
Source File: TestUtilities.java    From google-authenticator-android with Apache License 2.0 5 votes vote down vote up
/** 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);
  }
}
 
Example 8
Source File: InputMethodManager.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 9
Source File: TopBottomLocationManager.java    From Shield with MIT License 4 votes vote down vote up
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();
        }
    }
 
Example 10
Source File: ThreadedInputConnectionFactory.java    From 365browser with Apache License 2.0 4 votes vote down vote up
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);
                }
            });
        }
    });
}
 
Example 11
Source File: RootMatchers.java    From android-test with Apache License 2.0 4 votes vote down vote up
@Override
public boolean matchesSafely(View view) {
  return view.hasWindowFocus();
}