Example usage for android.widget ProgressBar setOnClickListener

List of usage examples for android.widget ProgressBar setOnClickListener

Introduction

In this page you can find the example usage for android.widget ProgressBar setOnClickListener.

Prototype

public void setOnClickListener(@Nullable OnClickListener l) 

Source Link

Document

Register a callback to be invoked when this view is clicked.

Usage

From source file:mp.paschalis.RegisterActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    app = (App) getApplication();/*ww  w .j av  a 2  s  . com*/

    buttonRegister = (Button) findViewById(R.id.buttonRegister);

    registerAsyncTask = new RegisterAsyncTask();

    registerUsername = (EditText) findViewById(R.id.editTextRegisterUsername);
    registerPassword = (EditText) findViewById(R.id.editTextRegisterPassword);
    registerConfirmPassword = (EditText) findViewById(R.id.editTextRegisterConfirmPassword);
    registerName = (EditText) findViewById(R.id.editTextRegisterName);
    registerSurname = (EditText) findViewById(R.id.editTextRegisterSurname);
    registerEmail = (EditText) findViewById(R.id.editTextRegisterEmail);
    registerPhone = (EditText) findViewById(R.id.editTextRegisterPhone);
    checkBoxNotificationsApplication = (CheckBox) findViewById(R.id.checkBoxRegisterNotificationsApplication);
    checkBoxNotificationsEmail = (CheckBox) findViewById(R.id.checkBoxRegisterNotificationsEmail);
    // textViewConfirmPassword = (TextView)
    // findViewById(R.id.textViewRegisterConfirmPassword);

    // Watch Field Changes
    registerUsername.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) {
            enableRegisterFields(RegisterFields.username);
        }
    });

    registerPassword.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) {
            enableRegisterFields(RegisterFields.password);
        }
    });

    registerConfirmPassword.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) {

            enableRegisterFields(RegisterFields.confirmPassword);
        }
    });

    registerName.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) {
            enableRegisterFields(RegisterFields.name);
        }
    });

    registerSurname.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) {
            enableRegisterFields(RegisterFields.surname);
        }
    });

    registerEmail.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) {
            enableRegisterFields(RegisterFields.email);
        }
    });

    registerPhone.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) {
            enableRegisterFields(RegisterFields.phone);

        }
    });

    buttonRegister.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // Try to register user to database

            // Hide Progress Bar, and reEnable button
            ProgressBar progressBarRegisterButton = (ProgressBar) findViewById(R.id.progressBarRegisterButton);

            buttonRegister.setClickable(false);
            progressBarRegisterButton.setVisibility(View.VISIBLE);
            buttonRegister.setVisibility(View.INVISIBLE);

            // Progress Bar Can cancel the task
            progressBarRegisterButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (!registerAsyncTask.isCancelled())
                        registerAsyncTask.cancel(true);

                }
            });

            // Login User
            if (!registerAsyncTask.isCancelled()) {
                registerAsyncTask = new RegisterAsyncTask();
            }
            registerAsyncTask.execute(app.library);

        }
    });

}