Example usage for android.text Editable toString

List of usage examples for android.text Editable toString

Introduction

In this page you can find the example usage for android.text Editable toString.

Prototype

public String toString();

Source Link

Document

Returns a string containing the characters in this sequence in the same order as this sequence.

Usage

From source file:com.example.naveen.dentalorder.ui.CustomerInfoFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mDrNameView.addTextChangedListener(new TextWatcher() {
        @Override/*from   ww w.  j  av  a  2s.c o m*/
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(CustomerInfoPage.DR_NAME_DATA_KEY,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });

    mNameView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(CustomerInfoPage.NAME_DATA_KEY,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });

    mAgeView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(CustomerInfoPage.AGE_DATA_KEY,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });

    mDateSend.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(CustomerInfoPage.DATE_SEND_DATA_KEY,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });

    mDateRequired.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(CustomerInfoPage.DATE_REQ_DATA_KEY,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });

    mMale.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mPage.getData().putString(CustomerInfoPage.SEX_DATA_KEY, (isChecked ? "Male" : "Female"));
            mPage.notifyDataChanged();
        }
    });

    mFemale.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mPage.getData().putString(CustomerInfoPage.SEX_DATA_KEY, (isChecked ? "Female" : "Male"));
            mPage.notifyDataChanged();
        }
    });
}

From source file:im.vector.fragments.ContactsListDialogFragment.java

/**
 * Init the dialog view.//from   w ww  . j  a  va 2 s.co  m
 * @param v the dialog view.
 */
void initView(View v) {
    mListView = ((ListView) v.findViewById(R.id.listView_contacts));

    // get the local contacts
    mLocalContacts = new ArrayList<Contact>(ContactsManager.getLocalContactsSnapshot(getActivity()));

    mAdapter = new ContactsListAdapter(getActivity(), R.layout.adapter_item_contact);

    // sort them
    Collections.sort(mLocalContacts, alphaComparator);

    mListView.setFastScrollAlwaysVisible(true);
    mListView.setFastScrollEnabled(true);
    mListView.setAdapter(mAdapter);

    refreshAdapter();

    // a button could be added to filter the contacts to display only the matrix users
    // but the lookup method is too slow (1 address / request).
    // it could be enabled when a batch request will be implemented
    /*
    final Button button = (Button)v.findViewById(R.id.button_matrix_users);
            
    button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View arg0) {
        mDisplayOnlyMatrixUsers = !mDisplayOnlyMatrixUsers;
            
        if (mDisplayOnlyMatrixUsers) {
            button.setBackgroundResource(R.drawable.matrix_user);
        } else {
            button.setBackgroundResource(R.drawable.ic_menu_allfriends);
        }
            
        refreshAdapter();
    }
    });*/

    final EditText editText = (EditText) v.findViewById(R.id.editText_contactBox);

    editText.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(android.text.Editable s) {
            ContactsListDialogFragment.this.mSearchPattern = s.toString();
            refreshAdapter();
        }

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

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    // tap on one of them
    // if he is a matrix, offer to start a chat
    // it he is not a matrix user, offer to invite him by email or SMS.
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            final Contact contact = mAdapter.getItem(position);
            final Activity activity = ContactsListDialogFragment.this.getActivity();

            if (contact.hasMatridIds(ContactsListDialogFragment.this.getActivity())) {
                final Contact.MXID mxid = contact.getFirstMatrixId();
                // The user is trying to leave with unsaved changes. Warn about that
                new AlertDialog.Builder(activity)
                        .setMessage(activity.getText(R.string.chat_with) + " " + mxid.mMatrixId + " ?")
                        .setPositiveButton("YES", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                activity.runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        CommonActivityUtils.goToOneToOneRoom(mxid.mAccountId, mxid.mMatrixId,
                                                activity, new SimpleApiCallback<Void>(getActivity()) {
                                                });
                                    }
                                });
                                dialog.dismiss();
                                // dismiss the member list
                                ContactsListDialogFragment.this.dismiss();

                            }
                        }).setNegativeButton("NO", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        }).create().show();

            } else {
                // invite the user
                final ArrayList<String> choicesList = new ArrayList<String>();

                if (AdapterUtils.canSendSms(activity)) {
                    choicesList.addAll(contact.mPhoneNumbers);
                }

                choicesList.addAll(contact.mEmails);

                // something to offer
                if (choicesList.size() > 0) {
                    final String[] labels = new String[choicesList.size()];

                    for (int index = 0; index < choicesList.size(); index++) {
                        labels[index] = choicesList.get(index);
                    }

                    new AlertDialog.Builder(activity).setItems(labels, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String value = labels[which];

                            // SMS ?
                            if (contact.mPhoneNumbers.indexOf(value) >= 0) {
                                AdapterUtils.launchSmsIntent(activity, value,
                                        activity.getString(R.string.invitation_message));
                            } else {
                                // emails
                                AdapterUtils.launchEmailIntent(activity, value,
                                        activity.getString(R.string.invitation_message));
                            }

                            // dismiss the member list
                            ContactsListDialogFragment.this.dismiss();
                        }
                    }).setTitle(activity.getString(R.string.invite_this_user_to_use_matrix)).show();
                }
            }
        }
    });
}

From source file:io.syng.activity.BaseActivity.java

private void initSearch() {
    mSearchTextView.addTextChangedListener(new TextWatcher() {
        @Override/*  ww  w . j a v  a  2s.  c o m*/
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            String searchValue = editable.toString();
            updateDAppList(searchValue);
        }
    });
    mSearchTextView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View view, int i, KeyEvent keyEvent) {
            if (keyEvent.getAction() == KeyEvent.ACTION_DOWN
                    && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                GeneralUtil.hideKeyBoard(mSearchTextView, BaseActivity.this);
                return true;
            }
            return false;
        }
    });
}

From source file:org.wso2.app.catalog.LoginActivity.java

/**
 * Initialize the Android IDP SDK by passing credentials,client ID and
 * client secret./*  w  ww  .j av a  2s .c o  m*/
 *
 * @param clientKey    client id value to access APIs..
 * @param clientSecret client secret value to access APIs.
 */
private void initializeIDPLib(String clientKey, String clientSecret) {

    String serverIP = Preference.getString(LoginActivity.this, Constants.PreferenceFlag.IP);
    if (serverIP != null && !serverIP.isEmpty()) {
        ServerConfig utils = new ServerConfig();
        utils.setServerIP(serverIP);
        String serverURL = utils.getServerURL(context) + Constants.OAUTH_ENDPOINT;
        Editable tenantDomain = etDomain.getText();

        if (tenantDomain != null && !tenantDomain.toString().trim().isEmpty()) {
            username = etUsername.getText().toString().trim()
                    + context.getResources().getString(R.string.intent_extra_at)
                    + tenantDomain.toString().trim();

        } else {
            username = etUsername.getText().toString().trim();
        }

        Preference.putString(context, Constants.CLIENT_ID, clientKey);
        Preference.putString(context, Constants.CLIENT_SECRET, clientSecret);

        CredentialInfo info = new CredentialInfo();
        info.setClientID(clientKey);
        info.setClientSecret(clientSecret);
        info.setUsername(username);
        try {
            info.setPassword(URLEncoder.encode(passwordVal, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            String msg = "error occurred while encoding password.";
            Log.e(TAG, msg, e);
        }
        info.setTokenEndPoint(serverURL);
        if (tenantDomain != null && !tenantDomain.toString().trim().isEmpty()) {
            info.setTenantDomain(tenantDomain.toString().trim());
        }

        IdentityProxy.getInstance().init(info, LoginActivity.this, this.getApplicationContext());
    }
}

From source file:eu.faircode.netguard.ActivityPro.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "Create");
    Util.setTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pro);//from  ww  w  .  j ava 2s .c  om

    getSupportActionBar().setTitle(R.string.title_pro);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

    // Initial state
    updateState();

    TextView tvLogTitle = findViewById(R.id.tvLogTitle);
    TextView tvFilterTitle = findViewById(R.id.tvFilterTitle);
    TextView tvNotifyTitle = findViewById(R.id.tvNotifyTitle);
    TextView tvSpeedTitle = findViewById(R.id.tvSpeedTitle);
    TextView tvThemeTitle = findViewById(R.id.tvThemeTitle);
    TextView tvAllTitle = findViewById(R.id.tvAllTitle);
    TextView tvDev1Title = findViewById(R.id.tvDev1Title);
    TextView tvDev2Title = findViewById(R.id.tvDev2Title);

    Linkify.TransformFilter filter = new Linkify.TransformFilter() {
        @Override
        public String transformUrl(Matcher match, String url) {
            return "";
        }
    };

    Linkify.addLinks(tvLogTitle, Pattern.compile(".*"), "http://www.netguard.me/#" + SKU_LOG, null, filter);
    Linkify.addLinks(tvFilterTitle, Pattern.compile(".*"), "http://www.netguard.me/#" + SKU_FILTER, null,
            filter);
    Linkify.addLinks(tvNotifyTitle, Pattern.compile(".*"), "http://www.netguard.me/#" + SKU_NOTIFY, null,
            filter);
    Linkify.addLinks(tvSpeedTitle, Pattern.compile(".*"), "http://www.netguard.me/#" + SKU_SPEED, null, filter);
    Linkify.addLinks(tvThemeTitle, Pattern.compile(".*"), "http://www.netguard.me/#" + SKU_THEME, null, filter);
    Linkify.addLinks(tvAllTitle, Pattern.compile(".*"), "http://www.netguard.me/#" + SKU_PRO1, null, filter);
    Linkify.addLinks(tvDev1Title, Pattern.compile(".*"), "http://www.netguard.me/#" + SKU_SUPPORT1, null,
            filter);
    Linkify.addLinks(tvDev2Title, Pattern.compile(".*"), "http://www.netguard.me/#" + SKU_SUPPORT2, null,
            filter);

    String android_id = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
    String challenge = (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? Build.SERIAL : "O3" + android_id);
    String seed = (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "NetGuard2" : "NetGuard3");

    // Challenge
    TextView tvChallenge = findViewById(R.id.tvChallenge);
    tvChallenge.setText(challenge);

    // Response
    try {
        final String response = Util.md5(challenge, seed);
        EditText etResponse = findViewById(R.id.etResponse);
        etResponse.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                // Do nothing
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // Do nothing
            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (response.equals(editable.toString().toUpperCase())) {
                    IAB.setBought(SKU_DONATION, ActivityPro.this);
                    updateState();
                }
            }
        });
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }

    try {
        iab = new IAB(new IAB.Delegate() {
            @Override
            public void onReady(final IAB iab) {
                Log.i(TAG, "IAB ready");
                try {
                    iab.updatePurchases();
                    updateState();

                    final Button btnLog = findViewById(R.id.btnLog);
                    final Button btnFilter = findViewById(R.id.btnFilter);
                    final Button btnNotify = findViewById(R.id.btnNotify);
                    final Button btnSpeed = findViewById(R.id.btnSpeed);
                    final Button btnTheme = findViewById(R.id.btnTheme);
                    final Button btnAll = findViewById(R.id.btnAll);
                    final Button btnDev1 = findViewById(R.id.btnDev1);
                    final Button btnDev2 = findViewById(R.id.btnDev2);

                    View.OnClickListener listener = new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            try {
                                int id = 0;
                                PendingIntent pi = null;
                                if (view == btnLog) {
                                    id = SKU_LOG_ID;
                                    pi = iab.getBuyIntent(SKU_LOG, false);
                                } else if (view == btnFilter) {
                                    id = SKU_FILTER_ID;
                                    pi = iab.getBuyIntent(SKU_FILTER, false);
                                } else if (view == btnNotify) {
                                    id = SKU_NOTIFY_ID;
                                    pi = iab.getBuyIntent(SKU_NOTIFY, false);
                                } else if (view == btnSpeed) {
                                    id = SKU_SPEED_ID;
                                    pi = iab.getBuyIntent(SKU_SPEED, false);
                                } else if (view == btnTheme) {
                                    id = SKU_THEME_ID;
                                    pi = iab.getBuyIntent(SKU_THEME, false);
                                } else if (view == btnAll) {
                                    id = SKU_PRO1_ID;
                                    pi = iab.getBuyIntent(SKU_PRO1, false);
                                } else if (view == btnDev1) {
                                    id = SKU_SUPPORT1_ID;
                                    pi = iab.getBuyIntent(SKU_SUPPORT1, true);
                                } else if (view == btnDev2) {
                                    id = SKU_SUPPORT2_ID;
                                    pi = iab.getBuyIntent(SKU_SUPPORT2, true);
                                }

                                if (id > 0 && pi != null)
                                    startIntentSenderForResult(pi.getIntentSender(), id, new Intent(), 0, 0, 0);
                            } catch (Throwable ex) {
                                Log.i(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                            }
                        }
                    };

                    btnLog.setOnClickListener(listener);
                    btnFilter.setOnClickListener(listener);
                    btnNotify.setOnClickListener(listener);
                    btnSpeed.setOnClickListener(listener);
                    btnTheme.setOnClickListener(listener);
                    btnAll.setOnClickListener(listener);
                    btnDev1.setOnClickListener(listener);
                    btnDev2.setOnClickListener(listener);

                    btnLog.setEnabled(true);
                    btnFilter.setEnabled(true);
                    btnNotify.setEnabled(true);
                    btnSpeed.setEnabled(true);
                    btnTheme.setEnabled(true);
                    btnAll.setEnabled(true);
                    btnDev1.setEnabled(true);
                    btnDev2.setEnabled(true);

                } catch (Throwable ex) {
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                }
            }
        }, this);
        iab.bind();
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
}

From source file:edu.vuum.mocca.ui.tags.EditTagsFragment.java

public TagsData makeTagsDataFromUI() {

    // local Editables
    Editable loginIdEditable = loginIdET.getText();
    Editable storyIdEditable = storyIdET.getText();
    Editable tagEditable = tagET.getText();

    long loginId = 0;
    long storyId = 0;
    String tag = "";

    // pull values from Editables
    loginId = Long.valueOf(loginIdEditable.toString());
    storyId = Long.valueOf(storyIdEditable.toString());
    tag = String.valueOf(tagEditable.toString());

    // return new TagsData object with
    return new TagsData(getUniqueKey(), loginId, storyId, tag);

}

From source file:org.wso2.iot.nfcprovisioning.AuthenticationActivity.java

/**
 * Initialize the Android IDP SDK by passing credentials,client ID and
 * client secret./*from ww w. ja v  a 2s.  c om*/
 *
 * @param clientKey    client id value to access APIs..
 * @param clientSecret client secret value to access APIs.
 */
private void initializeIDPLib(String clientKey, String clientSecret) {
    String serverIP = Preference.getString(context.getApplicationContext(), Constants.PreferenceFlag.IP);

    if (serverIP != null && !serverIP.isEmpty()) {
        String serverURL = serverIP + Constants.OAUTH_ENDPOINT;
        Editable tenantDomain = etDomain.getText();

        if (tenantDomain != null && !tenantDomain.toString().trim().isEmpty()) {
            username = etUsername.getText().toString().trim()
                    + context.getResources().getString(R.string.intent_extra_at)
                    + tenantDomain.toString().trim();

        } else {
            username = etUsername.getText().toString().trim();
        }

        Preference.putString(context, Constants.CLIENT_ID, clientKey);
        Preference.putString(context, Constants.CLIENT_SECRET, clientSecret);

        CredentialInfo info = new CredentialInfo();
        info.setClientID(clientKey);
        info.setClientSecret(clientSecret);
        info.setUsername(username);

        info.setPassword(passwordVal);
        info.setTokenEndPoint(serverURL);

        //adding device-specific scope
        String deviceScope = "device_" + deviceInfo.getDeviceId();
        info.setScopes(deviceScope);

        if (tenantDomain != null && !tenantDomain.toString().trim().isEmpty()) {
            info.setTenantDomain(tenantDomain.toString().trim());
        }

        IdentityProxy.getInstance().init(info, AuthenticationActivity.this, this.getApplicationContext());
    }
}

From source file:com.taokeba.fragment.RegistMoreFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    initSpinner();/*from   www .j av a  2s  .c o m*/
    //        
    //        String typeTemp = spStudentType.getSelectedItem().toString();
    //        mPage.getData().putString(RegistMorePage.STUDENT_TYPE_DATA_KEY, 
    //              typeTemp);
    //        mPage.notifyDataChanged();
    //        
    //        //
    //        String departmentTemp = spDepartment.getSelectedItem().toString();
    //        mPage.getData().putString(RegistMorePage.SCHOOL_DATA_KEY, 
    //              departmentTemp);
    //        mPage.notifyDataChanged();

    //
    tvMajor.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(RegistMorePage.MAJOR_DATA_KEY,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();

            //spinner
            initSpinner();
        }
    });

    //?
    tvStuClass.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(RegistMorePage.CLASS_DATA_KEY,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();

            //spinner
            initSpinner();
        }
    });

    //        
    etStartDate.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            new PopupWindows(getActivity(), etStartDate);
        }
    });

    //
    etEndDate.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            new PopupWindows(getActivity(), etEndDate);
        }
    });

}

From source file:org.mariotaku.twidere.fragment.DirectMessagesConversationFragment.java

private void send() {
    final Editable text = mEditText.getText();
    if (isEmpty(text))
        return;/*from  w  w  w. j  av a2s.  com*/
    final String message = text.toString();
    if (mValidator.isValidTweet(message)) {
        final long account_id = mArguments.getLong(INTENT_KEY_ACCOUNT_ID, -1);
        final long conversation_id = mArguments.getLong(INTENT_KEY_CONVERSATION_ID, -1);
        final String screen_name = mArguments.getString(INTENT_KEY_SCREEN_NAME);
        mTwitterWrapper.sendDirectMessage(account_id, screen_name, conversation_id, message);
        text.clear();
    }
}

From source file:eu.codeplumbers.cosi.wizards.firstrun.ConnectFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mUrl.addTextChangedListener(new TextWatcher() {
        @Override/*from   w  ww .  j a  v a2s. c  o m*/
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(ConnectPage.URL_DATA_KEY,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });

    mUsername.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(ConnectPage.USERNAME_DATA_KEY,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });

    mPassword.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(ConnectPage.PASSWORD_DATA_KEY,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });

    mDeviceName.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(ConnectPage.DEVICE_NAME_DATA_KEY,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });

    btnRegisterDevice.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            boolean mUrlOk = true;
            boolean mPasswordOk = true;

            if (mUrl.getText().toString().isEmpty()) {
                mUrl.setError("Cozy URL can not be empty!");
                mUrlOk = false;
            }
            if (mPassword.getText().toString().isEmpty()) {
                mPassword.setError("Your password can not be empty!");
                mPasswordOk = false;
            }

            if (mPasswordOk && mPasswordOk) {
                if (!mUrl.getText().toString().startsWith(Constants.HTTPS)) {
                    mUrl.setText(Constants.HTTPS + mUrl.getText().toString());
                }

                btnRegisterDevice.setEnabled(false);
                registerDevice();
            }
        }
    });
}