Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void askUserCredentials(String pWarning) {
- // starting the user credentials
- Log.v(tag, "askUserCredentials started ");
- // create the new dialog
- final Dialog dialogCredentials = new Dialog(this);
- //Set the content view to our xml layout
- dialogCredentials.setContentView(R.layout.dialog_login);
- // if there is a warning
- if (pWarning != null) {
- // show it instead of the regular text
- TextView dialogDescription = (TextView) dialogCredentials
- .findViewById(R.id.dialog_cred_description);
- dialogDescription.setText(pWarning);
- // also set it to red
- //dialogDescription.setTextColor(R.color.text_headline_main);
- }
- // Set the title of the dialog. this space is always drawn even if blank
- // so might as well use it
- dialogCredentials
- .setTitle(getString(R.string.LABEL_DIALOG_CREDENTIALS));
- // get password and username
- String lUsername = SharedPrefHandler.getPrefString(
- getApplicationContext(), SharedPrefHandler.USER_NAME);
- String lPassword = SharedPrefHandler.getPrefString(
- getApplicationContext(), SharedPrefHandler.USER_PASSWORD);
- // to get the values later set the reference to the fields
- final EditText txtPassword = (EditText) dialogCredentials
- .findViewById(R.id.edit_text_password);
- final EditText txtUsername = (EditText) dialogCredentials
- .findViewById(R.id.edit_text_username);
- // preset the values
- if (lUsername != null)
- txtUsername.setText(lUsername);
- if (lPassword != null)
- txtPassword.setText(lPassword);
- // Allow the dialog to be cancelable
- dialogCredentials.setCancelable(true);
- Button okButton = (Button) dialogCredentials
- .findViewById(R.id.dialog_cred_butt_OK);
- Button canceButton = (Button) dialogCredentials
- .findViewById(R.id.dialog_cred_butt_cancel);
- okButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- Log.v(tag, "Got some data - username:"
- + txtUsername.getText().toString() + "-Password: "
- + txtPassword.getText().toString());
- //close the dialog
- dialogCredentials.dismiss();
- // store them to the users settings
- SharedPrefHandler.storeSharedPref(getApplicationContext(),
- txtUsername.getText().toString(),
- SharedPrefHandler.USER_NAME);
- SharedPrefHandler.storeSharedPref(getApplicationContext(),
- txtPassword.getText().toString(),
- SharedPrefHandler.USER_PASSWORD);
- guiStatusMessage.setText("#Bitte warten.");
- //Start the sync in case the user just entered the credentials
- startSynchronisation();
- Log.i(tag,"started synch!"); //gets called after the function was executed
- }
- });
- // close the dialog if canceled
- canceButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- dialogCredentials.dismiss();
- }
- });
- dialogCredentials.show();
- }
- private void startSynchronisation() {
- try {
- if (myServerServiceBound && myServerService != null)
- myServerService.IgetUserData();
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement