Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. public class myWebClient extends WebViewClient
  2. {
  3. public void onReceivedHttpAuthRequest (WebView view, final HttpAuthHandler handler, String host, String realm)
  4. {
  5. Toast.makeText(getApplicationContext(), "AUTH REQUESTED", Toast.LENGTH_SHORT).show();
  6. super.onReceivedHttpAuthRequest(view, handler, host, realm);
  7.  
  8. if(!mWebViewDatabase.hasHttpAuthUsernamePassword())
  9. {
  10. // Authentication dialog prompt
  11.  
  12. AlertDialog.Builder builder = new AlertDialog.Builder(MyActivity.this);
  13. builder.setTitle("Sign In");
  14.  
  15. LinearLayout layout = new LinearLayout(MyActivity.this);
  16. layout.setOrientation(LinearLayout.VERTICAL);
  17.  
  18. //dialog.setView(layout);
  19.  
  20. // Set up the input
  21. final EditText userName = new EditText(getApplicationContext());
  22. // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
  23. userName.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL);
  24. userName.setHint("user name");
  25. userName.requestFocus();
  26. layout.addView(userName);
  27. //builder.setView(userName);
  28.  
  29. final EditText password = new EditText(getApplicationContext());
  30. // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
  31. password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
  32. password.setHint("password");
  33. password.requestFocus();
  34. layout.addView(password);
  35. builder.setView(layout);
  36.  
  37. // Set up the buttons
  38. builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
  39. @Override
  40. public void onClick(DialogInterface dialog, int which) {
  41. mUserName = userName.getText().toString();
  42. mPassword = password.getText().toString();
  43. handler.proceed(mUserName, mPassword);
  44. Log.d("Authentication", mUserName +"-->"+ mPassword);
  45. }
  46. });
  47. builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  48. @Override
  49. public void onClick(DialogInterface dialog, int which) {
  50. dialog.cancel();
  51.  
  52. }
  53. });
  54.  
  55. builder.show();
  56.  
  57. // end of Alert dialog prompt
  58.  
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement