use of com.cmput301w18t05.taskzilla.User in project Taskzilla by CMPUT301W18T05.
the class MainActivityTest method testSignUp.
public void testSignUp() {
MainActivity activity = (MainActivity) solo.getCurrentActivity();
solo.assertCurrentActivity("Wrong Activity", MainActivity.class);
solo.clickOnText("Sign Up");
solo.assertCurrentActivity("Wrong Activity", SignUpActivity.class);
// Wrong Info - Long username
solo.enterText((EditText) solo.getView(R.id.usernameField), "wowowowowowowowowowdkwodkwodwkodwkdowodkwdoksqsqw");
solo.enterText((EditText) solo.getView(R.id.nameField), "TestName");
solo.enterText((EditText) solo.getView(R.id.emailField), "Test@Email.com");
solo.enterText((EditText) solo.getView(R.id.phoneField), "1234567890");
solo.clickOnButton("Sign Up");
solo.assertCurrentActivity("Wrong Activity", SignUpActivity.class);
// Wrong Info - Illegal character in username
solo.clearEditText((EditText) solo.getView(R.id.usernameField));
solo.enterText((EditText) solo.getView(R.id.usernameField), "Test%^User");
solo.sleep(1000);
solo.clickOnButton("Sign Up");
solo.assertCurrentActivity("Wrong Activity", SignUpActivity.class);
// Wrong Info - Long name
solo.clearEditText((EditText) solo.getView(R.id.usernameField));
solo.enterText((EditText) solo.getView(R.id.usernameField), "TestUser");
solo.enterText((EditText) solo.getView(R.id.nameField), "TestNameTestNameTestNameTestNameTestNameTestNameTestNameTestNameTestName");
solo.clickOnButton("Sign Up");
solo.assertCurrentActivity("Wrong Activity", SignUpActivity.class);
// Wrong Info - Illegal character in name
solo.clearEditText((EditText) solo.getView(R.id.nameField));
solo.enterText((EditText) solo.getView(R.id.nameField), "$%**@(@)!)");
solo.sleep(1000);
solo.clickOnButton("Sign Up");
solo.assertCurrentActivity("Wrong Activity", SignUpActivity.class);
// Wrong Info - Email Invalid
solo.clearEditText((EditText) solo.getView(R.id.nameField));
solo.clearEditText((EditText) solo.getView(R.id.emailField));
solo.enterText((EditText) solo.getView(R.id.nameField), "TestName");
solo.enterText((EditText) solo.getView(R.id.emailField), "TestEmaillcom");
solo.clickOnButton("Sign Up");
solo.assertCurrentActivity("Wrong Activity", SignUpActivity.class);
// Wrong Info - Email Too Long
solo.clearEditText((EditText) solo.getView(R.id.emailField));
solo.enterText((EditText) solo.getView(R.id.emailField), "TestEmailcomTestEmailcomTestEmailcomTestEmailcomTestEmailcomTestEmailcomTestEmailcom");
solo.sleep(1000);
solo.clickOnButton("Sign Up");
solo.assertCurrentActivity("Wrong Activity", SignUpActivity.class);
// Wrong Info - Incorrect Phone Number
solo.clearEditText((EditText) solo.getView(R.id.emailField));
solo.enterText((EditText) solo.getView(R.id.emailField), "Test@Email.com");
solo.enterText((EditText) solo.getView(R.id.phoneField), "1290");
solo.clickOnButton("Sign Up");
solo.assertCurrentActivity("Wrong Activity", SignUpActivity.class);
// Valid Information
solo.clearEditText((EditText) solo.getView(R.id.phoneField));
solo.enterText((EditText) solo.getView(R.id.phoneField), "1234567890");
solo.sleep(1000);
solo.clickOnButton("Sign Up");
solo.assertCurrentActivity("Wrong Activity", MainActivity.class);
}
use of com.cmput301w18t05.taskzilla.User in project Taskzilla by CMPUT301W18T05.
the class RequestManagerTest method testAddUserRequest.
public void testAddUserRequest() {
AddUserRequest addUserRequest = new AddUserRequest(user);
RequestManager.getInstance().invokeRequest(ctx, addUserRequest);
assertTrue(addUserRequest.getResult());
}
use of com.cmput301w18t05.taskzilla.User in project Taskzilla by CMPUT301W18T05.
the class EditProfileActivity method onActivityResult.
/**
* When a photo is selected, return to the activity setting the photo
* for the current user
*
* @param requestCode
* @param resultCode
* @param data
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
try {
final Uri imageUri = data.getData();
final InputStream imageStream = this.getContentResolver().openInputStream(imageUri);
final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
File file = new File(imageUri.getPath());
// taken from https://stackoverflow.com/questions/2407565/bitmap-byte-size-after-decoding
// 2018-04-03
maxSize = 65536;
Log.i("ACTUAL SIZE", String.valueOf(selectedImage.getByteCount()));
Integer width = 1200;
Integer height = 1200;
Bitmap resizedImage;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
selectedImage.compress(Bitmap.CompressFormat.JPEG, 50, stream);
Log.i("size", String.valueOf(stream.size()));
while (stream.size() > maxSize) {
width = width - 200;
height = height - 200;
stream = new ByteArrayOutputStream();
resizedImage = Bitmap.createScaledBitmap(selectedImage, width, height, false);
resizedImage.compress(Bitmap.CompressFormat.JPEG, 50, stream);
Log.i("size", String.valueOf(stream.size()));
}
byte[] byteImage;
byteImage = stream.toByteArray();
String image = Base64.encodeToString(byteImage, Base64.DEFAULT);
user.setPhoto(new Photo(image));
profilePicture.setImageBitmap(user.getPhoto().StringToBitmap());
Log.i("test", user.getPhoto().toString());
} catch (Exception e) {
Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(this, "You haven't picked a photo", Toast.LENGTH_LONG).show();
}
}
use of com.cmput301w18t05.taskzilla.User in project Taskzilla by CMPUT301W18T05.
the class MainActivity method onCreate.
/**
* Activity uses the activity_main.xml layout
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*Controller*/
mainActivityController = new MainActivityController(this);
/*initial singleton current user*/
user.getInstance();
/* initalize request manager */
RequestManager.getInstance().setContext(getApplicationContext());
IntentFilter connectionFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
getApplicationContext().registerReceiver(RequestManager.getInstance(), connectionFilter);
/* setup view vars */
loginButton = findViewById(R.id.logInButton);
signupButton = findViewById(R.id.SignUp);
usernameView = findViewById(R.id.usernameText);
passwordView = findViewById(R.id.passwordText);
cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
// when enter is pressed when typing in password field, go automatically to log in button
// code gotten from https://stackoverflow.com/questions/4451374/use-enter-key-on-softkeyboard-instead-of-clicking-button
passwordView.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch(keyCode) {
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
logInButtonOnclick();
return true;
default:
break;
}
}
return false;
}
});
/* login action */
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
logInButtonOnclick();
}
});
/*Sign up button*/
signupButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mainActivityController.signUp();
}
});
/*Auto Login*/
loadLogin();
if (foundUser != null && !foundUser.getUsername().equalsIgnoreCase("TestUser") && !foundUser.getUsername().equalsIgnoreCase("TestUserOne")) {
ni = cm.getActiveNetworkInfo();
if (ni != null && ni.isConnected()) {
currentUser.getRealInstance().setUser(getUser(foundUser.getUsername()));
} else {
currentUser.getRealInstance().setUser(foundUser);
}
mainActivityController.logIn();
finish();
}
}
use of com.cmput301w18t05.taskzilla.User in project Taskzilla by CMPUT301W18T05.
the class ProfileActivity method setValues.
/**
* retrieves id from previous activity and get the user from elastic search
* setting up the views on the profile activity
*/
public void setValues() {
userID = getIntent().getStringExtra("user id");
this.profileController = new ProfileController(this.findViewById(android.R.id.content), this);
profileController.setUserID(userID);
profileController.getUserRequest();
user = profileController.getUser();
name = user.getName();
try {
email = user.getEmail().toString();
phone = user.getPhone().toString();
} catch (Exception e) {
email = "No Email";
phone = "No Number";
}
numRequests = profileController.getNumberOfRequests(user.getUsername());
numTasksDone = profileController.getNumberOfTasksDone(user.getUsername());
nameField.setText(name);
emailField.setText(email);
phoneField.setText(phone);
numRequestsField.setText(numRequests);
numTasksDoneField.setText(numTasksDone);
providerRatingField.setText(String.format(Locale.CANADA, "%.1f", user.getProviderRating()));
requesterRatingField.setText(String.format(Locale.CANADA, "%.1f", user.getRequesterRating()));
try {
profilePicture.setImageBitmap(user.getPhoto().StringToBitmap());
} catch (Exception e) {
Photo defaultPhoto = new Photo("");
profilePicture.setImageBitmap(defaultPhoto.StringToBitmap());
}
}
Aggregations