@Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
   getSupportActionBar().hide();
   ParseAnalytics.trackAppOpenedInBackground(getIntent());
   mUserSwitch = (Switch) findViewById(R.id.typeSwitch);
   // check if user is logged in if not lets create a new User
   if (ParseUser.getCurrentUser() == null) {
     ParseAnonymousUtils.logIn(
         new LogInCallback() {
           @Override
           public void done(ParseUser user, ParseException e) {
             if (e == null) {
               Log.d(getPackageName(), "Anon user Logged in");
             } else {
               Log.d(getPackageName(), "Anon User login error " + e.getMessage());
             }
           }
         });
   }
   // check if user is rider or driver
   else {
     if (ParseUser.getCurrentUser().get("riderOrDriver") != null) {
       redirectUser();
     }
   }
 }
示例#2
0
  private void checkUser() {
    if (ParseAnonymousUtils.isLinked(ParseUser.getCurrentUser())) {
      Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
      startActivity(intent);
      finish();

    } else {
      ParseUser currentUser = ParseUser.getCurrentUser();
      if (currentUser != null) {
        Intent intent = new Intent(SplashActivity.this, TabActivity.class);
        intent.putExtra("user", currentUser.getUsername());
        startActivity(intent);
        finish();
      } else {
        Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
        startActivity(intent);
        finish();
      }
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_profile);
    setupToolbar();

    // Connect views
    editName = (EditText) findViewById(R.id.edit_name);
    editDateOfBirth = (EditText) findViewById(R.id.edit_date_of_birth);
    editPhone = (EditText) findViewById(R.id.edit_phone_number);
    editIDCardNumber = (EditText) findViewById(R.id.edit_id_card_number);
    editDescription = (EditText) findViewById(R.id.edit_description);
    editAvatar = (ImageView) findViewById(R.id.edit_avatar);
    editGender = (Spinner) findViewById(R.id.edit_gender);
    buttonChangeAvatar = (Button) findViewById(R.id.button_change_avatar);

    // Set up button change avatar
    buttonChangeAvatar.setOnClickListener(this);

    // set up date of birth input field
    editDateOfBirth.setFocusable(false);
    editDateOfBirth.setClickable(true);
    editDateOfBirth.setOnClickListener(this);

    // Determine whether the current user is an anonymous user
    if (!ParseAnonymousUtils.isLinked(ParseUser.getCurrentUser())) {

      // If current user is not anonymous user
      // Get current user data from Parse.com
      ParseUser currentUser = ParseUser.getCurrentUser();
      if (currentUser != null) {

        // get user information
        editName.setText(currentUser.getString("name"));
        editDateOfBirth.setText(currentUser.getString("date_of_birth"));
        if (currentUser.getString("gender").equals("Male")) {
          editGender.setSelection(1);
        } else {
          editGender.setSelection(2);
        }
        editPhone.setText(currentUser.getString("phone"));
        editDescription.setText(currentUser.getString("description"));
        editIDCardNumber.setText(currentUser.getString("id_card_number"));

        // get avatar
        ParseFile file = currentUser.getParseFile("avatar");
        file.getDataInBackground(
            new GetDataCallback() {
              @Override
              public void done(byte[] bytes, ParseException e) {
                Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                editAvatar.setImageBitmap(bitmap);
              }
            });
      }
    }

    // Set up gender spinner
    List<String> list = new ArrayList<String>();
    list.add("Male");
    list.add("Female");
    ArrayAdapter<String> dataAdapter =
        new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    editGender.setAdapter(dataAdapter);

    // Set up progress dialog
    progressDialog = new ProgressDialog(this);
    progressDialog.setMessage(this.getResources().getString(R.string.wait));
    progressDialog.setCanceledOnTouchOutside(false);
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
      case R.id.done:
        if (editName.getText().toString().trim().equals("")) {
          Toast.makeText(
                  EditProfileActivity.this,
                  getString(R.string.please_enter_your_name),
                  Toast.LENGTH_SHORT)
              .show();
          editName.requestFocus();
          return false;
        }

        if (editPhone.getText().toString().equals("")) {
          Toast.makeText(
                  EditProfileActivity.this,
                  getString(R.string.please_enter_your_phone_number),
                  Toast.LENGTH_SHORT)
              .show();
          editPhone.requestFocus();
          return false;
        }

        if (editIDCardNumber.getText().toString().trim().equals("")) {
          Toast.makeText(
                  EditProfileActivity.this,
                  getString(R.string.please_enter_your_id_card_number),
                  Toast.LENGTH_SHORT)
              .show();
          editIDCardNumber.requestFocus();
          return false;
        }

        if (editDescription.getText().toString().trim().equals("")) {
          Toast.makeText(
                  EditProfileActivity.this,
                  getString(R.string.you_must_tell_something_about_yourself),
                  Toast.LENGTH_SHORT)
              .show();
          editDescription.requestFocus();
          return false;
        }

        progressDialog.show();

        // Check if we should signUpUser or updateUser and then send user to MapViewActivity

        if (ParseAnonymousUtils.isLinked(ParseUser.getCurrentUser())) {
          signUpUser();
        } else {
          // If current user is not anonymous user
          // Get current user data from Parse.com
          ParseUser currentUser = ParseUser.getCurrentUser();
          if (currentUser != null) {
            // Send logged in user to MapViewActivity.class
            updateUser();

          } else {
            // Send user to LoginSignupActivity.class
            signUpUser();
          }
        }

        return true;
      default:
        return super.onOptionsItemSelected(item);
    }
  }