Search in sources :

Example 26 with User

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);
}
Also used : MainActivity(com.cmput301w18t05.taskzilla.activity.MainActivity)

Example 27 with User

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());
}
Also used : AddUserRequest(com.cmput301w18t05.taskzilla.request.command.AddUserRequest)

Example 28 with User

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();
    }
}
Also used : Bitmap(android.graphics.Bitmap) InputStream(java.io.InputStream) Photo(com.cmput301w18t05.taskzilla.Photo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Uri(android.net.Uri) File(java.io.File)

Example 29 with User

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();
    }
}
Also used : KeyEvent(android.view.KeyEvent) IntentFilter(android.content.IntentFilter) MainActivityController(com.cmput301w18t05.taskzilla.controller.MainActivityController) View(android.view.View) TextView(android.widget.TextView)

Example 30 with User

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());
    }
}
Also used : ProfileController(com.cmput301w18t05.taskzilla.controller.ProfileController) Photo(com.cmput301w18t05.taskzilla.Photo)

Aggregations

View (android.view.View)13 Task (com.cmput301w18t05.taskzilla.Task)11 AddUserRequest (com.cmput301w18t05.taskzilla.request.command.AddUserRequest)8 AlertDialog (android.support.v7.app.AlertDialog)6 ListView (android.widget.ListView)6 TextView (android.widget.TextView)6 Photo (com.cmput301w18t05.taskzilla.Photo)6 EditText (android.widget.EditText)5 AddTaskRequest (com.cmput301w18t05.taskzilla.request.command.AddTaskRequest)5 ArrayList (java.util.ArrayList)5 Intent (android.content.Intent)4 ColorDrawable (android.graphics.drawable.ColorDrawable)4 ActionBar (android.support.v7.app.ActionBar)4 RecyclerView (android.support.v7.widget.RecyclerView)4 AdapterView (android.widget.AdapterView)4 ImageButton (android.widget.ImageButton)4 User (com.cmput301w18t05.taskzilla.User)4 DialogInterface (android.content.DialogInterface)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 ArrayAdapter (android.widget.ArrayAdapter)3