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

The following examples show how to use android.view.View#hasWindowFocus() . These examples are extracted from open source projects. 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
/**
 * 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
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
@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
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
@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
@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
/** 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
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 Project: Shield   File: TopBottomLocationManager.java    License: 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
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 Project: android-test   File: RootMatchers.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean matchesSafely(View view) {
  return view.hasWindowFocus();
}