Advertisement
Guest User

Untitled

a guest
Feb 12th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. @Override
  2. protected void onCreate(Bundle savedInstanceState) { //where you initialize your activity
  3. super.onCreate(savedInstanceState);
  4. setContentView(R.layout.activity_login);//this tell the ...which file it is using
  5.  
  6. //to log app activation
  7. FacebookSdk.sdkInitialize(getApplicationContext());
  8. AppEventsLogger.activateApp(this);
  9.  
  10. //reference all the fields and buttons on the xml file
  11. final EditText etUserName = (EditText) findViewById(R.id.etUserName);// this is declaring the varible etAge as a final editText and will not be assigned to anything else and to find the text view
  12. final EditText etPassWord = (EditText) findViewById(R.id.etPassWord);
  13. final Button bLogin = (Button) findViewById(R.id.bLogin);
  14. final TextView RegisterLink = (TextView) findViewById(R.id.RegisterLink);
  15.  
  16. RegisterLink.setOnClickListener(new View.OnClickListener() {
  17. @Override
  18. public void onClick(View v) {
  19. Intent registerIntent = new Intent(LoginActivity.this, RegisterActivity.class);
  20. LoginActivity.this.startActivity(registerIntent);
  21. }
  22. });
  23.  
  24. bLogin.setOnClickListener(new View.OnClickListener(){
  25. @Override
  26. public void onClick(View v) {
  27. final String username = etUserName.getText().toString();
  28. final String password = etPassWord.getText().toString();
  29.  
  30. Response.Listener<String> responseListener = new Response.Listener<String>() {
  31. @Override
  32. public void onResponse(String response) {
  33. try {
  34. JSONObject jsonResponce = new JSONObject(response);
  35. boolean success = jsonResponce.getBoolean("success");
  36.  
  37. if (success){
  38. String name = jsonResponce.getString("name");
  39. String username = jsonResponce.getString("password");
  40.  
  41. Intent intent = new Intent(LoginActivity.this, MainUserArea.class);//this is to pass the name and age to the new activity
  42. intent.putExtra("name", name);
  43. intent.putExtra("username", username);
  44.  
  45. LoginActivity.this.startActivity(intent);
  46. }else{
  47. //if not successsfull print error page
  48. AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
  49. builder.setMessage("Login Failed")
  50. .setNegativeButton("Retry",null)
  51. .create()
  52. .show();
  53. }
  54.  
  55. } catch (JSONException e) {
  56. e.printStackTrace();
  57. }
  58. }
  59. };
  60.  
  61. LoginRequest LoginRequest = new LoginRequest(username, password, responseListener);
  62. // to deal with the request
  63. RequestQueue queue = Volley.newRequestQueue(LoginActivity.this);
  64. queue.add(LoginRequest);
  65.  
  66. //the google login
  67.  
  68.  
  69. }
  70. });
  71.  
  72. //the facebook login code
  73. @Override
  74. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  75. View view = inflater.inflate(R.layout.splash, container, false);
  76.  
  77. loginButton = (LoginButton) view.findViewById(R.id.login_button);
  78. loginButton.setReadPermissions("email");
  79. // If using in a fragment
  80. loginButton.setFragment(this);
  81. // Other app specific specialization
  82.  
  83. // Callback registration
  84. loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
  85. @Override
  86. public void onSuccess(LoginResult loginResult) {
  87. // App code
  88. }
  89.  
  90. @Override
  91. public void onCancel() {
  92. // App code
  93. }
  94.  
  95. @Override
  96. public void onError(FacebookException exception) {
  97. // App code
  98. }
  99. });
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement