Java Code Examples for android.view.View#setOnFocusChangeListener()
The following examples show how to use
android.view.View#setOnFocusChangeListener() .
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: AppInstalledPresenter.java From LeanbackTvSample with MIT License | 6 votes |
@Override public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) { if (mContext == null) { mContext = parent.getContext(); } View view = LayoutInflater.from(mContext).inflate(R.layout.item_app_installed, parent, false); view.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { v.findViewById(R.id.tv_app_name).setSelected(hasFocus); } }); return new ViewHolder(view); }
Example 2
Source File: MagicForm.java From MagicForm with Apache License 2.0 | 6 votes |
private void setupFormFieldOnFocusChangeMode(final FormField formField) { final View view = formField.getView(); if (isFieldValid(formField)) { addValidField(formField); } view.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { validateField(formField); } } }); setupTextChangeListener(formField, false); }
Example 3
Source File: RvItemClickSupport.java From Aria with Apache License 2.0 | 6 votes |
@Override public void onChildViewAttachedToWindow(View view) { if (mOnItemClickListener != null) { view.setOnClickListener(mOnClickListener); } if (mOnItemLongClickListener != null) { view.setOnLongClickListener(mOnLongClickListener); } if (mOnItemTouchListener != null) { view.setOnTouchListener(mOnTouchListener); } if (mOnItemFocusChangeListener != null) { view.setOnFocusChangeListener(mOnFocusChangeListener); } if (mOnItemKeyListener != null) { view.setOnKeyListener(mOnKeyListener); } }
Example 4
Source File: WXComponent.java From weex-uikit with MIT License | 6 votes |
protected final void addFocusChangeListener(OnFocusChangeListener l){ View view; if(l != null && (view = getRealView()) != null) { if( mFocusChangeListeners == null){ mFocusChangeListeners = new ArrayList<>(); view.setFocusable(true); view.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { for (OnFocusChangeListener listener : mFocusChangeListeners){ if(listener != null){ listener.onFocusChange(hasFocus); } } } }); } mFocusChangeListeners.add(l); } }
Example 5
Source File: ItemBridgeAdapter.java From TvRecyclerView with Apache License 2.0 | 6 votes |
@NonNull @Override public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { Presenter presenter = mPresenters.get(viewType); Presenter.ViewHolder presenterVh = presenter.onCreateViewHolder(parent); View view = presenterVh.view; ViewHolder viewHolder = new ViewHolder(presenter, view, presenterVh); if (mAdapterListener != null) { mAdapterListener.onCreate(viewHolder); } View presenterView = viewHolder.mHolder.view; if (presenterView != null) { viewHolder.mFocusChangeListener.mChainedListener = presenterView.getOnFocusChangeListener(); presenterView.setOnFocusChangeListener(viewHolder.mFocusChangeListener); } if (mFocusHighlight != null) { mFocusHighlight.onInitializeView(view); } return viewHolder; }
Example 6
Source File: MountState.java From litho with Apache License 2.0 | 5 votes |
static void setComponentFocusChangeListener(View v, ComponentFocusChangeListener listener) { if (v instanceof ComponentHost) { ((ComponentHost) v).setComponentFocusChangeListener(listener); } else { v.setOnFocusChangeListener(listener); v.setTag(R.id.component_focus_change_listener, listener); } }
Example 7
Source File: RecyclerViewTV.java From Android-tv-widget with Apache License 2.0 | 5 votes |
@Override public void onChildAttachedToWindow(View child) { // 设置单击事件,修复. if (!child.hasOnClickListeners()) { child.setOnClickListener(mItemListener); } // 设置焦点事件,修复. if (child.getOnFocusChangeListener() == null) { child.setOnFocusChangeListener(mItemListener); } }
Example 8
Source File: TvRecyclerView.java From TvRecyclerView with Apache License 2.0 | 5 votes |
@Override public void onChildAttachedToWindow(View child) { if (!ViewCompat.hasOnClickListeners(child)) { child.setOnClickListener(mItemListener); } child.setOnLongClickListener(mItemListener); if (child.getOnFocusChangeListener() == null) { child.setOnFocusChangeListener(mItemListener); } }
Example 9
Source File: EnterTreatment.java From HAPP with GNU General Public License v3.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.fragment_manual_treatment, container, false); spinner_treatment_type = (Spinner) rootView.findViewById(R.id.treatmentSpinner); spinner_notes = (Spinner) rootView.findViewById(R.id.noteSpinner); editText_treatment_time = (EditText) rootView.findViewById(R.id.treatmentTime); editText_treatment_date = (EditText) rootView.findViewById(R.id.treatmentDate); editText_treatment_value = (EditText) rootView.findViewById(R.id.treatmentValue); rootView.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean b) { if(b) { if (view == editText_treatment_date) { treatmentDatePickerDialog.show(); } else if (view == editText_treatment_time) { treatmentTimePicker.show(); } //view.clearFocus(); } } }); setupPickers(rootView); return rootView; }
Example 10
Source File: Blorm.java From Blorm with MIT License | 5 votes |
public void whenChangeFocusOn(View submittedItem) { submittedItem.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) new Blorm(validations, field, errorMessages, validates, onSuccess, onError).onSubmitted(); } }); }
Example 11
Source File: ActivityDlgActionInput.java From LibreTasks with Apache License 2.0 | 5 votes |
private void initializeUI(Bundle bundle) { setContentView(R.layout.activity_dlg_action_input); Button btnOk = (Button) findViewById(R.id.activity_dlg_action_input_btnOk); btnOk.setOnClickListener(listenerBtnClickOk); Button btnAttributes = (Button) findViewById(R.id.activity_dlg_action_input_btnAttributes); btnAttributes.setOnClickListener(listenerBtnClickAttributes); Button btnHelp = (Button) findViewById(R.id.activity_dlg_action_input_btnHelp); btnHelp.setOnClickListener(listenerBtnClickHelp); llContent = (LinearLayout) findViewById(R.id.activity_dlg_action_input_llDynamicContent); // Add dynamic content now based on our action type. ModelAction modelAction = RuleBuilder.instance().getChosenModelAction(); ArrayList<DataType> ruleActionDataOld = RuleBuilder.instance().getChosenRuleActionDataOld(); viewItems = ActionParameterViewFactory.buildUIFromAction(modelAction, ruleActionDataOld, this); llContent.addView(viewItems.getLayout()); ArrayList<View> textEdits = llContent.getFocusables(View.FOCUS_FORWARD); for (View t : textEdits) { t.setOnFocusChangeListener(editTextFocusChangeListener); } try { viewItems.loadState(bundle); } catch (Exception e) { Log.e(TAG, "Failed during loadState", e); } setTitle(modelAction.getTypeName()); }
Example 12
Source File: FullScreenContext.java From air-ane-fullscreen with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Resets UI and window handlers to default state */ public void resetUi() { final View decorView = getDecorView(); if (decorView != null) { decorView.setOnFocusChangeListener(getOnFocusChangeListener()); decorView.setOnSystemUiVisibilityChangeListener(null); } init(); setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); }
Example 13
Source File: MongolInputMethodManager.java From mongol-library with MIT License | 5 votes |
/** * Registers an editor to receive input from the custom keyboard * * @param editor EditText or MongolEditText * @param allowSystemKeyboard sets whether the system keyboard will popup when an editor is focused */ @SuppressWarnings("WeakerAccess") public void addEditor(View editor, boolean allowSystemKeyboard) { // editor must be MongolEditText or EditText if (!(editor instanceof EditText) && !(editor instanceof MongolEditText)) { throw new RuntimeException("MongolInputMethodManager " + "only supports adding a MongolEditText or EditText " + "at this time. You added: " + editor); } if (mRegisteredEditors == null) { mRegisteredEditors = new ArrayList<>(); } // don't add the same view twice for (RegisteredEditor item : mRegisteredEditors) { if (item.view == editor) return; } // give the editor's input connection to the keyboard when editor is focused editor.setOnFocusChangeListener(focusListener); // TODO if hiding the keyboard on back button then may need to add a touch listener to edit texts too // get extra updates from MongolEditText // TODO is there any way for us to get these updates from EditText? if (editor instanceof MongolEditText) { ((MongolEditText) editor).setOnMongolEditTextUpdateListener(this); } // TODO set allow system keyboard to show if hasn't been set setAllowSystemKeyboard(editor, allowSystemKeyboard); // add editor mRegisteredEditors.add(new RegisteredEditor(editor, allowSystemKeyboard)); mCurrentEditor = editor; }
Example 14
Source File: Workspace.java From LaunchEnr with GNU General Public License v3.0 | 5 votes |
public void addToCustomContentPage(View customContent, CustomContentCallbacks callbacks, String description) { if (getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID) < 0) { throw new RuntimeException("Expected custom content screen to exist"); } // Add the custom content to the full screen custom page CellLayout customScreen = getScreenWithId(CUSTOM_CONTENT_SCREEN_ID); int spanX = customScreen.getCountX(); int spanY = customScreen.getCountY(); CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, spanX, spanY); lp.canReorder = false; lp.isFullscreen = true; if (customContent instanceof Insettable) { ((Insettable)customContent).setInsets(mInsets); } // Verify that the child is removed from any existing parent. if (customContent.getParent() instanceof ViewGroup) { ViewGroup parent = (ViewGroup) customContent.getParent(); parent.removeView(customContent); } customScreen.removeAllViews(); customContent.setFocusable(true); customContent.setOnKeyListener(new FullscreenKeyEventListener()); customContent.setOnFocusChangeListener(mLauncher.mFocusHandler .getHideIndicatorOnFocusListener()); customScreen.addViewToCellLayout(customContent, 0, 0, lp, true); mCustomContentDescription = description; mCustomContentCallbacks = callbacks; }
Example 15
Source File: GridBuilder.java From GridBuilder with Apache License 2.0 | 4 votes |
/** * 向GridLayout容器中添加Grid元素 * * @param gridItem Grid元素 */ private GridBuilder addItem(GridItem gridItem) { View itemLayout = null; if (null != mOnViewCreateCallBack) { itemLayout = mOnViewCreateCallBack.onViewCreate(mLayoutInflater, null == mGridViewHolder ? null : mGridViewHolder.getConvertView(), gridItem); } if (null == itemLayout) { return this; } GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(); // 优先根据预先取得的width/height设置,但不影响跨列/行数 layoutParams.width = (gridItem.getWidth() > 0 ? gridItem.getWidth() : gridItem.getColumnSpec() * mBaseWidth) + ((gridItem.getColumnSpec() > 1 && gridItem.getWidth() <= 0 ? mHorizontalMargin * (gridItem.getColumnSpec() - 1) : 0)); layoutParams.height = (gridItem.getHeight() > 0 ? gridItem.getHeight() : gridItem.getRowSpec() * mBaseHeight) + ((gridItem.getRowSpec() > 1 && gridItem.getWidth() <= 0 ? mVerticalMargin * (gridItem.getRowSpec() - 1) : 0)); if (gridItem.getWidth() <= 0) { gridItem.setWidth(layoutParams.width); } if (gridItem.getHeight() <= 0) { gridItem.setHeight(layoutParams.height); } layoutParams.rowSpec = GridLayout.spec(gridItem.getRow(), gridItem.getRowSpec()); layoutParams.columnSpec = GridLayout.spec(gridItem.getColumn(), gridItem.getColumnSpec()); // 设置每个item间距,最外层间距也需要设置(因为需要体现边缘item的scale效果) if (gridItem.getRow() > 0) { layoutParams.topMargin = mVerticalMargin; } if (gridItem.getColumn() > 0) { layoutParams.leftMargin = mHorizontalMargin; } itemLayout.setLayoutParams(layoutParams); itemLayout.setFocusable(true); itemLayout.setClickable(true); itemLayout.setOnFocusChangeListener(this); itemLayout.setOnClickListener(this); itemLayout.setOnKeyListener(mOnKeyListener); itemLayout.setSoundEffectsEnabled(false); if (mGridLayout.getChildCount() == 0 && gridItem == mGridItemList.get(0)) { itemLayout.setTag(GridItem.TAG_FIRST_ITEM); } this.mGridLayout.addView(itemLayout); return this; }
Example 16
Source File: MaterialDialog.java From DialogUtil with Apache License 2.0 | 4 votes |
public void setView(View view) { LinearLayout l = (LinearLayout) mAlertDialogWindow.findViewById(R.id.contentView); l.removeAllViews(); ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); view.setLayoutParams(layoutParams); view.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { mAlertDialogWindow.setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); // show imm InputMethodManager imm = (InputMethodManager) mContext.getSystemService( Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); } }); l.addView(view); if (view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; for (int i = 0; i < viewGroup.getChildCount(); i++) { if (viewGroup.getChildAt(i) instanceof EditText) { EditText editText = (EditText) viewGroup.getChildAt(i); editText.setFocusable(true); editText.requestFocus(); editText.setFocusableInTouchMode(true); } } for (int i = 0; i < viewGroup.getChildCount(); i++) { if (viewGroup.getChildAt(i) instanceof AutoCompleteTextView) { AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) viewGroup .getChildAt(i); autoCompleteTextView.setFocusable(true); autoCompleteTextView.requestFocus(); autoCompleteTextView.setFocusableInTouchMode(true); } } } }
Example 17
Source File: CollectionView.java From TiCollectionView with MIT License | 4 votes |
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { // To prevent undesired "focus" and "blur" events during layout caused // by ListView temporarily taking focus, we will disable focus events until // layout has finished. // First check for a quick exit. listView can be null, such as if window closing. // Starting with API 18, calling requestFocus() will trigger another layout pass of the listview, // resulting in an infinite loop. Here we check if the view is already focused, and stop the loop. if (listView == null || (Build.VERSION.SDK_INT >= 18 && listView != null && !changed && viewFocused)) { viewFocused = false; super.onLayout(changed, left, top, right, bottom); return; } OnFocusChangeListener focusListener = null; View focusedView = listView.findFocus(); int cursorPosition = -1; if (focusedView != null) { OnFocusChangeListener listener = focusedView.getOnFocusChangeListener(); if (listener != null && listener instanceof TiUIView) { //Before unfocus the current editText, store cursor position so //we can restore it later if (focusedView instanceof EditText) { cursorPosition = ((EditText)focusedView).getSelectionStart(); } focusedView.setOnFocusChangeListener(null); focusListener = listener; } } //We are temporarily going to block focus to descendants //because LinearLayout on layout will try to find a focusable descendant if (focusedView != null) { listView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); } super.onLayout(changed, left, top, right, bottom); //Now we reset the descendant focusability listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); TiViewProxy viewProxy = proxy; if (viewProxy != null && viewProxy.hasListeners(TiC.EVENT_POST_LAYOUT)) { viewProxy.fireEvent(TiC.EVENT_POST_LAYOUT, null); } // Layout is finished, re-enable focus events. if (focusListener != null) { // If the configuration changed, we manually fire the blur event if (changed) { focusedView.setOnFocusChangeListener(focusListener); focusListener.onFocusChange(focusedView, false); } else { //Ok right now focus is with listView. So set it back to the focusedView viewFocused = true; focusedView.requestFocus(); focusedView.setOnFocusChangeListener(focusListener); //Restore cursor position if (cursorPosition != -1) { ((EditText)focusedView).setSelection(cursorPosition); } } } }
Example 18
Source File: MaterialDialog.java From pius1 with GNU Lesser General Public License v3.0 | 4 votes |
public void setView(View view) { LinearLayout l = (LinearLayout) mAlertDialogWindow.findViewById(R.id.contentView); l.removeAllViews(); ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); view.setLayoutParams(layoutParams); view.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { mAlertDialogWindow.setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); // show imm InputMethodManager imm = (InputMethodManager) mContext.getSystemService( Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); } }); l.addView(view); if (view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; for (int i = 0; i < viewGroup.getChildCount(); i++) { if (viewGroup.getChildAt(i) instanceof EditText) { EditText editText = (EditText) viewGroup.getChildAt(i); editText.setFocusable(true); editText.requestFocus(); editText.setFocusableInTouchMode(true); } } for (int i = 0; i < viewGroup.getChildCount(); i++) { if (viewGroup.getChildAt(i) instanceof AutoCompleteTextView) { AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) viewGroup .getChildAt(i); autoCompleteTextView.setFocusable(true); autoCompleteTextView.requestFocus(); autoCompleteTextView.setFocusableInTouchMode(true); } } } }
Example 19
Source File: LoginActivity.java From TuentiTV with Apache License 2.0 | 4 votes |
private void configureScaleAnimator(View v_account_container) { View ib_account = v_account_container.findViewById(R.id.ib_account); View tv_account_name = v_account_container.findViewById(R.id.tv_account_name); ib_account.setOnFocusChangeListener(new OnFocusChangeAccountListener(tv_account_name)); }
Example 20
Source File: FocusVisual.java From aedict with GNU General Public License v3.0 | 2 votes |
/** * Registers this listener to a view. * * @param view * the view, not null. * @return this */ public FocusVisual registerTo(final View view) { view.setFocusable(true); view.setOnFocusChangeListener(this); return this; }