Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- protected void onCreate(Bundle savedInstanceState) { //where you initialize your activity
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);//this tell the ...which file it is using
- //to log app activation
- FacebookSdk.sdkInitialize(getApplicationContext());
- AppEventsLogger.activateApp(this);
- //reference all the fields and buttons on the xml file
- 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
- final EditText etPassWord = (EditText) findViewById(R.id.etPassWord);
- final Button bLogin = (Button) findViewById(R.id.bLogin);
- final TextView RegisterLink = (TextView) findViewById(R.id.RegisterLink);
- RegisterLink.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent registerIntent = new Intent(LoginActivity.this, RegisterActivity.class);
- LoginActivity.this.startActivity(registerIntent);
- }
- });
- bLogin.setOnClickListener(new View.OnClickListener(){
- @Override
- public void onClick(View v) {
- final String username = etUserName.getText().toString();
- final String password = etPassWord.getText().toString();
- Response.Listener<String> responseListener = new Response.Listener<String>() {
- @Override
- public void onResponse(String response) {
- try {
- JSONObject jsonResponce = new JSONObject(response);
- boolean success = jsonResponce.getBoolean("success");
- if (success){
- String name = jsonResponce.getString("name");
- String username = jsonResponce.getString("password");
- Intent intent = new Intent(LoginActivity.this, MainUserArea.class);//this is to pass the name and age to the new activity
- intent.putExtra("name", name);
- intent.putExtra("username", username);
- LoginActivity.this.startActivity(intent);
- }else{
- //if not successsfull print error page
- AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
- builder.setMessage("Login Failed")
- .setNegativeButton("Retry",null)
- .create()
- .show();
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- };
- LoginRequest LoginRequest = new LoginRequest(username, password, responseListener);
- // to deal with the request
- RequestQueue queue = Volley.newRequestQueue(LoginActivity.this);
- queue.add(LoginRequest);
- //the google login
- }
- });
- //the facebook login code
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.splash, container, false);
- loginButton = (LoginButton) view.findViewById(R.id.login_button);
- loginButton.setReadPermissions("email");
- // If using in a fragment
- loginButton.setFragment(this);
- // Other app specific specialization
- // Callback registration
- loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
- @Override
- public void onSuccess(LoginResult loginResult) {
- // App code
- }
- @Override
- public void onCancel() {
- // App code
- }
- @Override
- public void onError(FacebookException exception) {
- // App code
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement