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

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

源代码1 项目: weex-uikit   文件: WXComponent.java
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);
  }
}
 
源代码2 项目: TvRecyclerView   文件: ItemBridgeAdapter.java
@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;
}
 
源代码3 项目: Aria   文件: RvItemClickSupport.java
@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);
  }
}
 
源代码4 项目: MagicForm   文件: MagicForm.java
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);
}
 
源代码5 项目: LeanbackTvSample   文件: AppInstalledPresenter.java
@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);
}
 
源代码6 项目: litho   文件: MountState.java
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);
  }
}
 
源代码7 项目: LaunchEnr   文件: Workspace.java
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;
}
 
源代码8 项目: mongol-library   文件: MongolInputMethodManager.java
/**
 * 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;
}
 
源代码9 项目: air-ane-fullscreen   文件: FullScreenContext.java
/**
 * 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);
}
 
源代码10 项目: LibreTasks   文件: ActivityDlgActionInput.java
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());
}
 
源代码11 项目: Blorm   文件: Blorm.java
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();
    }
  });
}
 
源代码12 项目: HAPP   文件: EnterTreatment.java
@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;
}
 
源代码13 项目: TvRecyclerView   文件: TvRecyclerView.java
@Override
public void onChildAttachedToWindow(View child) {
    if (!ViewCompat.hasOnClickListeners(child)) {
        child.setOnClickListener(mItemListener);
    }
    child.setOnLongClickListener(mItemListener);
    if (child.getOnFocusChangeListener() == null) {
        child.setOnFocusChangeListener(mItemListener);
    }

}
 
源代码14 项目: Android-tv-widget   文件: RecyclerViewTV.java
@Override
public void onChildAttachedToWindow(View child) {
    // 设置单击事件,修复.
    if (!child.hasOnClickListeners()) {
        child.setOnClickListener(mItemListener);
    }
    // 设置焦点事件,修复.
    if (child.getOnFocusChangeListener() == null) {
        child.setOnFocusChangeListener(mItemListener);
    }
}
 
源代码15 项目: pius1   文件: MaterialDialog.java
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);
                   }
               }
           }
       }
 
源代码16 项目: GridBuilder   文件: GridBuilder.java
/**
 * 向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;
}
 
源代码17 项目: DialogUtil   文件: MaterialDialog.java
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);
            }
        }
    }
}
 
源代码18 项目: TiCollectionView   文件: CollectionView.java
@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);
			}
		}
	}
}
 
源代码19 项目: TuentiTV   文件: LoginActivity.java
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));
}
 
源代码20 项目: aedict   文件: FocusVisual.java
/**
 * 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;
}
 
 方法所在类
 同类方法