Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. private void askUserCredentials(String pWarning) {
  2. // starting the user credentials
  3. Log.v(tag, "askUserCredentials started ");
  4.  
  5. // create the new dialog
  6. final Dialog dialogCredentials = new Dialog(this);
  7.  
  8. //Set the content view to our xml layout
  9. dialogCredentials.setContentView(R.layout.dialog_login);
  10.  
  11. // if there is a warning
  12. if (pWarning != null) {
  13. // show it instead of the regular text
  14. TextView dialogDescription = (TextView) dialogCredentials
  15. .findViewById(R.id.dialog_cred_description);
  16.  
  17. dialogDescription.setText(pWarning);
  18.  
  19. // also set it to red
  20. //dialogDescription.setTextColor(R.color.text_headline_main);
  21. }
  22.  
  23. // Set the title of the dialog. this space is always drawn even if blank
  24. // so might as well use it
  25. dialogCredentials
  26. .setTitle(getString(R.string.LABEL_DIALOG_CREDENTIALS));
  27.  
  28. // get password and username
  29. String lUsername = SharedPrefHandler.getPrefString(
  30. getApplicationContext(), SharedPrefHandler.USER_NAME);
  31. String lPassword = SharedPrefHandler.getPrefString(
  32. getApplicationContext(), SharedPrefHandler.USER_PASSWORD);
  33.  
  34. // to get the values later set the reference to the fields
  35. final EditText txtPassword = (EditText) dialogCredentials
  36. .findViewById(R.id.edit_text_password);
  37. final EditText txtUsername = (EditText) dialogCredentials
  38. .findViewById(R.id.edit_text_username);
  39.  
  40. // preset the values
  41. if (lUsername != null)
  42. txtUsername.setText(lUsername);
  43. if (lPassword != null)
  44. txtPassword.setText(lPassword);
  45.  
  46. // Allow the dialog to be cancelable
  47. dialogCredentials.setCancelable(true);
  48.  
  49. Button okButton = (Button) dialogCredentials
  50. .findViewById(R.id.dialog_cred_butt_OK);
  51. Button canceButton = (Button) dialogCredentials
  52. .findViewById(R.id.dialog_cred_butt_cancel);
  53.  
  54. okButton.setOnClickListener(new View.OnClickListener() {
  55.  
  56. @Override
  57. public void onClick(View v) {
  58. // TODO Auto-generated method stub
  59. Log.v(tag, "Got some data - username:"
  60. + txtUsername.getText().toString() + "-Password: "
  61. + txtPassword.getText().toString());
  62.  
  63. //close the dialog
  64. dialogCredentials.dismiss();
  65.  
  66. // store them to the users settings
  67. SharedPrefHandler.storeSharedPref(getApplicationContext(),
  68. txtUsername.getText().toString(),
  69. SharedPrefHandler.USER_NAME);
  70. SharedPrefHandler.storeSharedPref(getApplicationContext(),
  71. txtPassword.getText().toString(),
  72. SharedPrefHandler.USER_PASSWORD);
  73.  
  74. guiStatusMessage.setText("#Bitte warten.");
  75.  
  76. //Start the sync in case the user just entered the credentials
  77. startSynchronisation();
  78.  
  79. Log.i(tag,"started synch!"); //gets called after the function was executed
  80. }
  81. });
  82.  
  83. // close the dialog if canceled
  84. canceButton.setOnClickListener(new View.OnClickListener() {
  85.  
  86. @Override
  87. public void onClick(View v) {
  88.  
  89. dialogCredentials.dismiss();
  90.  
  91. }
  92. });
  93.  
  94. dialogCredentials.show();
  95. }
  96.  
  97. private void startSynchronisation() {
  98.  
  99.  
  100. try {
  101. if (myServerServiceBound && myServerService != null)
  102.  
  103. myServerService.IgetUserData();
  104. } catch (RemoteException e) {
  105. // TODO Auto-generated catch block
  106. e.printStackTrace();
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement