Java Code Examples for android.view.View#OnFocusChangeListener

The following examples show how to use android.view.View#OnFocusChangeListener . 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: LoginViewModel.java    From android-MVVM-DataBinding-FormExample with MIT License 6 votes vote down vote up
@VisibleForTesting
public void init() {
    login = new LoginForm();
    onFocusEmail =  new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View view, boolean focused) {
            EditText et = (EditText) view;
            if (et.getText().length() > 0 && !focused) {
                login.isEmailValid(true);
            }
        }
    };

    onFocusPassword = new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View view, boolean focused) {
            EditText et = (EditText) view;
            if (et.getText().length() > 0 && !focused) {
                login.isPasswordValid(true);
            }
        }
    };
}
 
Example 2
Source File: FragmentCharacteristicDetail.java    From EFRConnect-android with Apache License 2.0 6 votes vote down vote up
private View.OnFocusChangeListener getHexFocusChangeListener() {
    View.OnFocusChangeListener listener = new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                hexEdit.setText(hexEdit.getText().toString().replaceAll("\\s+", ""));
            } else {
                int textLength = hexEdit.getText().toString().length();
                String hexValue;
                if (textLength % 2 == 1) {
                    String temp = hexEdit.getText().toString();
                    hexValue = temp.substring(0, textLength - 1) + "0" + temp.charAt(textLength - 1);
                } else {
                    hexValue = hexEdit.getText().toString();
                }
                byte[] value = hexToByteArray(hexValue);
                hexEdit.setText(Converters.getHexValue(value));
            }
            updateSaveButtonState();
        }
    };
    return listener;
}
 
Example 3
Source File: CompositeListener.java    From TextFieldBoxes with Apache License 2.0 5 votes vote down vote up
@Override
public void onFocusChange(View view, boolean b) {

    for(View.OnFocusChangeListener listener:registeredListeners) {
        listener.onFocusChange(view, b);
    }
}
 
Example 4
Source File: FullScreenContext.java    From air-ane-fullscreen with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public View.OnFocusChangeListener getOnFocusChangeListener()
{
	if (_onFocusChangeListener == null)
	{
		_onFocusChangeListener = getDecorView().getOnFocusChangeListener();
	}
	
	return _onFocusChangeListener; 
}
 
Example 5
Source File: AllAppsContainerView.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    boolean isRtl = Utilities.isRtl(getResources());
    mAdapter.setRtl(isRtl);
    mContent = findViewById(R.id.content);

    // This is a focus listener that proxies focus from a view into the list view.  This is to
    // work around the search box from getting first focus and showing the cursor.
    View.OnFocusChangeListener focusProxyListener = new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                mAppsRecyclerView.requestFocus();
            }
        }
    };
    mSearchBarContainerView = (ViewGroup) findViewById(R.id.search_box_container);
    mSearchBarContainerView.setOnFocusChangeListener(focusProxyListener);
    mContainerView = findViewById(R.id.all_apps_container);
    mContainerView.setOnFocusChangeListener(focusProxyListener);
    mRevealView = findViewById(R.id.all_apps_reveal);

    // Load the all apps recycler view
    mAppsRecyclerView = (AllAppsRecyclerView) findViewById(R.id.apps_list_view);
    mAppsRecyclerView.setApps(mApps);
    mAppsRecyclerView.setLayoutManager(mLayoutManager);
    mAppsRecyclerView.setAdapter(mAdapter);
    mAppsRecyclerView.setHasFixedSize(true);
    if (mItemDecoration != null) {
        mAppsRecyclerView.addItemDecoration(mItemDecoration);
    }
    setScroller();
    updateGridTheme();
    updateSectionStrategy();
    updateBackgroundAndPaddings();
}
 
Example 6
Source File: MyAdapter.java    From TVSample with Apache License 2.0 5 votes vote down vote up
public MyAdapter(Context context, List<DetailInfo> dataset, int id, View.OnFocusChangeListener onFocusChangeListener) {
    super();
    mContext = context;
    mDataset = dataset;
    this.id = id;
    this.mOnFocusChangeListener = onFocusChangeListener;
}
 
Example 7
Source File: MyAdapter.java    From TvWidget with Apache License 2.0 5 votes vote down vote up
public MyAdapter(Context context, String[] dataset,int id,View.OnFocusChangeListener onFocusChangeListener) {
    super();
    mContex = context;
    mDataset = dataset;
    this.id=id;
    this.mOnFocusChangeListener=onFocusChangeListener;
}
 
Example 8
Source File: PostContentViewBinder.java    From smart-farmer-android with Apache License 2.0 5 votes vote down vote up
public PostContentViewBinder(String hint, @NonNull MultiTypeAdapter listAdapter,
                             @NonNull Items items,
                             @NonNull UploadPresenter<AlbumFile, JsonObject, ?, ?> presenter,
                             @NonNull Collection<AlbumPicturesGridAdapter> adapterHolder,
                             @NonNull View.OnFocusChangeListener listener,
                             @NonNull PictureActionCallback pictureActionCallback) {
    this.contentHint = hint;
    this.listAdapter = listAdapter;
    this.items = items;
    this.presenter = presenter;
    this.adapterHolder = adapterHolder;
    this.listener = listener;
    this.pictureActionCallback = pictureActionCallback;
}
 
Example 9
Source File: ViewGroupFocusHelper.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the alpha of this FocusIndicatorHelper to 0 when a view with this listener
 * receives focus.
 */
public View.OnFocusChangeListener getHideIndicatorOnFocusListener() {
    return new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                endCurrentAnimation();
                setCurrentView(null);
                setAlpha(0);
                invalidateDirty();
            }
        }
    };
}
 
Example 10
Source File: FragmentCharacteristicDetail.java    From EFRConnect-android with Apache License 2.0 4 votes vote down vote up
private void addRawValue() {
    // read only fields and value display for characteristic (inline)
    LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View readableFieldsForInline = layoutInflater.inflate(R.layout.characteristic_value_read_only, null);

    hex = readableFieldsForInline.findViewById(R.id.hex_readonly);
    ascii = readableFieldsForInline.findViewById(R.id.ascii_readonly);
    decimal = readableFieldsForInline.findViewById(R.id.decimal_readonly);

    ImageView hexCopyIV = readableFieldsForInline.findViewById(R.id.hex_copy);
    ImageView asciiCopyIV = readableFieldsForInline.findViewById(R.id.ascii_copy);
    ImageView decimalCopyIV = readableFieldsForInline.findViewById(R.id.decimal_copy);

    hex.setId(EDIT_NOT_CLEAR_ID);
    ascii.setId(EDIT_NOT_CLEAR_ID);
    decimal.setId(EDIT_NOT_CLEAR_ID);

    hex.setKeyListener(null);
    ascii.setKeyListener(null);
    decimal.setKeyListener(null);

    hex.setText(Converters.getHexValue(value));
    ascii.setText(Converters.getAsciiValue(value));
    decimal.setText(Converters.getDecimalValue(value));

    rawValueViews.add(hex);
    rawValueViews.add(ascii);
    rawValueViews.add(decimal);

    setCopyListener(hex, hexCopyIV);
    setCopyListener(ascii, asciiCopyIV);
    setCopyListener(decimal, decimalCopyIV);

    valuesLayout.addView(readableFieldsForInline);

    if (writeable || writeableWithoutResponse) {
        View writableFieldsForDialog = layoutInflater.inflate(R.layout.characteristic_value, null);

        hexEdit = writableFieldsForDialog.findViewById(R.id.hex_edit);
        asciiEdit = writableFieldsForDialog.findViewById(R.id.ascii_edit);
        decimalEdit = writableFieldsForDialog.findViewById(R.id.decimal_edit);

        ImageView hexPasteIV = writableFieldsForDialog.findViewById(R.id.hex_paste);
        ImageView asciiPasteIV = writableFieldsForDialog.findViewById(R.id.ascii_paste);
        ImageView decimalPasteIV = writableFieldsForDialog.findViewById(R.id.decimal_paste);

        editTexts.add(hexEdit);
        editTexts.add(asciiEdit);
        editTexts.add(decimalEdit);

        TextWatcher hexWatcher = getHexTextWatcher();
        TextWatcher decWatcher = getDecTextWatcher();
        TextWatcher asciiWatcher = getAsciiTextWatcher();

        View.OnFocusChangeListener hexListener = getHexFocusChangeListener();

        hexEdit.setOnFocusChangeListener(hexListener);
        WriteCharacteristic commiter = new WriteCharacteristic();
        hexEdit.setOnEditorActionListener(commiter);
        asciiEdit.setOnEditorActionListener(commiter);
        decimalEdit.setOnEditorActionListener(commiter);

        hexEdit.addTextChangedListener(hexWatcher);
        asciiEdit.addTextChangedListener(asciiWatcher);
        decimalEdit.addTextChangedListener(decWatcher);

        setPasteListener(hexEdit, hexPasteIV, HEX_ID);
        setPasteListener(asciiEdit, asciiPasteIV, ASCII_ID);
        setPasteListener(decimalEdit, decimalPasteIV, DECIMAL_ID);

        updateSaveButtonState();

        if (writableFieldsContainer != null) {
            writableFieldsContainer.removeAllViews();
            writableFieldsContainer.addView(writableFieldsForDialog);
        }

    }
}
 
Example 11
Source File: DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void onQueryTextFocusChange(View.OnFocusChangeListener arg) {
  return BaseDSL.attr("onQueryTextFocusChange", arg);
}
 
Example 12
Source File: CountrySelectFragment.java    From InviZible with GNU General Public License v3.0 4 votes vote down vote up
private CountriesViewHolder(View itemView) {
    super(itemView);

    tvCountry = itemView.findViewById(R.id.tvCountry);
    chbCountry = itemView.findViewById(R.id.chbCountry);
    cardCountry = itemView.findViewById(R.id.cardCountry);
    cardCountry.setClickable(true);

    View.OnClickListener onClickListener = v -> {
        if (!isCountryInList(getAdapterPosition())) {
            setChecked(getAdapterPosition());
            notifyItemChanged(getAdapterPosition());
        } else if (isCountryInList(getAdapterPosition())) {
            removeCheck(countriesListCurrent.get(getAdapterPosition()).countryCode);
            notifyItemChanged(getAdapterPosition());
        }
    };
    cardCountry.setOnClickListener(onClickListener);

    CompoundButton.OnCheckedChangeListener activeListener = (buttonView, isChecked) -> {

        if (!isCountryInList(getAdapterPosition()) && isChecked) {
            setChecked(getAdapterPosition());
            notifyItemChanged(getAdapterPosition());
        } else if (isCountryInList(getAdapterPosition()) && !isChecked) {
            removeCheck(countriesListCurrent.get(getAdapterPosition()).countryCode);
            notifyItemChanged(getAdapterPosition());
        }
    };
    chbCountry.setOnCheckedChangeListener(activeListener);

    chbCountry.setFocusable(false);
    cardCountry.setFocusable(true);
    View.OnFocusChangeListener onFocusChangeListener = (v, hasFocus) -> {
        if (hasFocus) {
            ((CardView) v).setCardBackgroundColor(getResources().getColor(R.color.colorSelected));
        } else {
            if (getAdapterPosition() % 2 == 0) {
                ((CardView) v).setCardBackgroundColor(getResources().getColor(R.color.colorSecond));
            } else {
                ((CardView) v).setCardBackgroundColor(getResources().getColor(R.color.colorFirst));
            }
        }

    };

    cardCountry.setOnFocusChangeListener(onFocusChangeListener);

    llTorCountry = itemView.findViewById(R.id.llTorCountry);

    if (getActivity() != null) {
        cardTorCountryFragment = getActivity().findViewById(R.id.cardTorCountryFragment);
    }

}
 
Example 13
Source File: DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void onFocusChange(View.OnFocusChangeListener arg) {
  return BaseDSL.attr("onFocusChange", arg);
}
 
Example 14
Source File: DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void onFocusChange(View.OnFocusChangeListener arg) {
  return BaseDSL.attr("onFocusChange", arg);
}
 
Example 15
Source File: AppCompatv7DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void onQueryTextFocusChange(View.OnFocusChangeListener arg) {
  return BaseDSL.attr("onQueryTextFocusChange", arg);
}
 
Example 16
Source File: OptionItemAdapter.java    From TVSample with Apache License 2.0 4 votes vote down vote up
public OptionItemAdapter(Context context, int id, View.OnFocusChangeListener onFocusChangeListener) {
    super();
    mContext = context;
    this.id = id;
    this.mOnFocusChangeListener = onFocusChangeListener;
}
 
Example 17
Source File: AbstractCard.java    From Pimp_my_Z1 with GNU General Public License v2.0 4 votes vote down vote up
public View.OnFocusChangeListener getFocusListener() {
    return focusListener;
}
 
Example 18
Source File: LoginViewModel.java    From android-MVVM-DataBinding-FormExample with MIT License 4 votes vote down vote up
public View.OnFocusChangeListener getEmailOnFocusChangeListener() {
    return onFocusEmail;
}
 
Example 19
Source File: CardEdit.java    From Pimp_my_Z1 with GNU General Public License v2.0 4 votes vote down vote up
public CardEdit(String title, String desc, String titleColor, TextWatcher textWatcher, View.OnFocusChangeListener focusListener) {
    super(title, desc, titleColor, textWatcher, focusListener);
}
 
Example 20
Source File: UnlockTorAppsFragment.java    From InviZible with GNU General Public License v3.0 4 votes vote down vote up
private TorAppsViewHolder(View itemView) {
    super(itemView);

    imgTorApp = itemView.findViewById(R.id.imgTorApp);
    tvTorAppName = itemView.findViewById(R.id.tvTorAppName);
    tvTorAppPackage = itemView.findViewById(R.id.tvTorAppPackage);
    swTorApp = itemView.findViewById(R.id.swTorApp);
    cardTorApps = itemView.findViewById(R.id.cardTorApp);
    cardTorApps.setFocusable(true);
    lLayoutTorApps = itemView.findViewById(R.id.llayoutTorApps);

    if (getActivity() != null) {
        cardTorAppFragment = getActivity().findViewById(R.id.cardTorAppFragment);
    }

    CompoundButton.OnCheckedChangeListener onCheckedChangeListener = (compoundButton, newValue) -> {
        setActive(getAdapterPosition(), newValue);
        isChanged = true;
    };
    swTorApp.setOnCheckedChangeListener(onCheckedChangeListener);
    swTorApp.setFocusable(false);


    View.OnClickListener onClickListener = view -> {
        int appPosition = getAdapterPosition();
        boolean appActive = getItem(appPosition).active;
        setActive(appPosition, !appActive);
        mAdapter.notifyItemChanged(appPosition);
        isChanged = true;
    };

    cardTorApps.setOnClickListener(onClickListener);
    View.OnFocusChangeListener onFocusChangeListener = (view, inFocus) -> {
        if (inFocus) {
            ((CardView) view).setCardBackgroundColor(getResources().getColor(R.color.colorSecond));
        } else {
            ((CardView) view).setCardBackgroundColor(getResources().getColor(R.color.colorFirst));
        }
    };
    cardTorApps.setOnFocusChangeListener(onFocusChangeListener);
    cardTorApps.setCardBackgroundColor(getResources().getColor(R.color.colorFirst));
}