@Override public boolean onTouch(View v, MotionEvent event) { if (!v.hasFocus()) { v.requestFocus(); } return false; } });
attributes.add(new ViewAttribute<>("HasFocus", view.hasFocus())); attributes.add(new ViewAttribute<>("HasFocusable", view.hasFocusable())); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
webview.requestFocus(View.FOCUS_DOWN); webview.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } return false; } });
webView.requestFocus(View.FOCUS_DOWN); webView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } return false; } });
mReqToken = mTwitter.getOAuthRequestToken(CALLBACK_URL); WebView webView = new WebView(this); webView.requestFocus(View.FOCUS_DOWN); webView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } return false; } }); webView.loadUrl(mReqToken.getAuthenticationURL()); mainLayout.removeAllViews(); mainLayout.addView(webView);
public S hasFocus() { isNotNull(); assertThat(actual.hasFocus()) // .overridingErrorMessage("Expected to have focus but was not focused") // .isTrue(); return myself; }
public S hasNoFocus() { isNotNull(); assertThat(actual.hasFocus()) // .overridingErrorMessage("Expected to not have focus but was focused") // .isFalse(); return myself; }
@Test public void shouldFocus() throws Exception { final List<String> transcript = new ArrayList<>(); view.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { transcript.add(hasFocus ? "Gained focus" : "Lost focus"); } }); assertFalse(view.isFocused()); assertFalse(view.hasFocus()); assertThat(transcript).isEmpty(); view.requestFocus(); assertFalse(view.isFocused()); assertFalse(view.hasFocus()); assertThat(transcript).isEmpty(); view.setFocusable(true); view.requestFocus(); assertTrue(view.isFocused()); assertTrue(view.hasFocus()); assertThat(transcript).containsExactly("Gained focus"); transcript.clear(); shadowOf(view) .setMyParent(new LinearLayout(context)); // we can never lose focus unless a parent can // take it view.clearFocus(); assertFalse(view.isFocused()); assertFalse(view.hasFocus()); assertThat(transcript).containsExactly("Lost focus"); }
@Test public void clearFocus_shouldRecursivelyClearTheFocusOfAllChildren() throws Exception { child3a.requestFocus(); root.clearFocus(); assertFalse(child3a.hasFocus()); assertFalse(child3.hasFocus()); assertFalse(root.hasFocus()); root.requestFocus(); root.clearFocus(); assertFalse(root.hasFocus()); }
@Test public void hasFocus_shouldReturnTrueIfAnyChildHasFocus() throws Exception { makeFocusable(root, child1, child2, child3, child3a, child3b); assertFalse(root.hasFocus()); child1.requestFocus(); assertTrue(root.hasFocus()); child1.clearFocus(); assertFalse(child1.hasFocus()); assertTrue(root.hasFocus()); child3b.requestFocus(); assertTrue(root.hasFocus()); child3b.clearFocus(); assertFalse(child3b.hasFocus()); assertFalse(child3.hasFocus()); assertTrue(root.hasFocus()); child2.requestFocus(); assertFalse(child3.hasFocus()); assertTrue(child2.hasFocus()); assertTrue(root.hasFocus()); root.requestFocus(); assertTrue(root.hasFocus()); }
webview.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } return false; } });
mWebView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } return false; } });
webview.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } return false; } });
et1.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if(v.hasFocus()) { int len = et1.getEditableText().toString().trim().length(); if(len > 1) et1.setSelection((int)len/2); } } });
public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } return false; }
private void showKeyboard(View view) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1 && view.hasFocus()) { view.clearFocus(); } view.requestFocus(); InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(view, 0); }
private void showKeyboard(View view) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1 && view.hasFocus()) { view.clearFocus(); } view.requestFocus(); InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(view, 0); }
@Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP && !v.hasFocus()) { v.performClick(); } return false; }
@Override @Implementation public boolean hasFocus() { if (super.hasFocus()) return true; for (View child : children) { if (child.hasFocus()) return true; } return false; }
@Override public void removeChatBox(boolean animToRight) { if (!searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text).hasFocus()) { hideSoftKeyBoard(); } AnimationHelper.hideViewX(chatBox, animToRight); //show fab button CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); RemoveViewsOnScroll removeViewsOnScroll = (RemoveViewsOnScroll) layoutParams.getBehavior(); removeViewsOnScroll.showView(fab); }