Philio / PinEntryView

A pin entry view widget for Android.
222 stars 83 forks source link

setOnPinEnteredListener #34

Open Louroj opened 8 years ago

Louroj commented 8 years ago

I'm currently trying to put a setOnPinEnteredListener on my app so it calls a webservice to validate the password but unfortunately it is not recognized.

here is what I have:

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
import com.ggs.managerroom.MainActivity;
import com.mycomapany.myapp.R;
import me.philio.pinentry.PinEntryView;

public class PasswordFragment extends Fragment {
    private PinEntryView pinEntryView;

@Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        loadControls();

        pinEntryView.setOnPinEnteredListener(new PinEntryView.OnPinEnteredListener() {
           @Override
            public void onPinEntered(String pin) {
                Toast.makeText(getActivity(), "Pin entered: " + pin, Toast.LENGTH_LONG).show();
            }
        });
    }

    protected void loadControls() {
        MainActivity activity;
        activity = (MainActivity) getActivity();
       pinEntryView = (PinEntryView)activity.findViewById(R.id.pin_entry);
    }
....
}

Any help on what I might be doing wrong?

here is a image to see what my problem is:

https://gyazo.com/8396ff4586e70d2822510b22565ca8a2

Isabellle commented 8 years ago

Same here

Lawrence-Windsor commented 7 years ago

If this is of any help. setOnPinEnteredListener doesn't seem to exists in the library so what i used was textchanged here is an example that works

            pinEntryView.addTextChangedListener(new TextWatcher() {
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {}

                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

                @Override
                public void afterTextChanged(Editable s) {
                    if(s.length() == 4){
                        InputMethodManager imm = (InputMethodManager)
                        getActivity().getSystemService(getActivity().INPUT_METHOD_SERVICE);
                        imm.hideSoftInputFromWindow(
                                pinEntryView.getWindowToken(), 0);
                    }
                }
            });
volax commented 7 years ago

You need to download library sources: https://github.com/Philio/PinEntryView/tree/master/pinentry and include 'pinentry' project into application's build.gradle as a dependency:

dependencies { .... compile project(':pinentry') }

setOnPinEnteredListener is here on line 284: https://github.com/Philio/PinEntryView/blob/master/pinentry/src/main/java/me/philio/pinentry/PinEntryView.java

UPDATE1: You can also include a git repo dependency with this guy: https://github.com/bat-cha/gradle-plugin-git-dependencies

UPDATE2: My favorite way now: https://jitpack.io/#Philio/PinEntryView/master

dmast3r commented 6 years ago

Thanks @volax works like charm.