Search in sources :

Example 6 with BackendlessUser

use of com.backendless.BackendlessUser in project Android-SDK by Backendless.

the class BackendlessUserFactory method createObject.

@Override
public Object createObject(IAdaptingType iAdaptingType) {
    if (iAdaptingType instanceof NamedObject)
        iAdaptingType = ((NamedObject) iAdaptingType).getTypedObject();
    if (iAdaptingType.getClass().getName().equals("weborb.reader.NullType"))
        return null;
    ReferenceCache refCache = ReferenceCache.getInstance();
    BackendlessUser backendlessUser;
    if (refCache.hasObject(iAdaptingType, BackendlessUser.class)) {
        return refCache.getObject(iAdaptingType, BackendlessUser.class);
    } else {
        backendlessUser = new BackendlessUser();
        refCache.addObject(iAdaptingType, BackendlessUser.class, backendlessUser);
    }
    HashMap props;
    try {
        props = (HashMap) iAdaptingType.adapt(HashMap.class);
    } catch (Throwable t) {
        props = new HashMap();
    }
    backendlessUser.setProperties(props);
    return backendlessUser;
}
Also used : BackendlessUser(com.backendless.BackendlessUser) ReferenceCache(weborb.reader.ReferenceCache) HashMap(java.util.HashMap) NamedObject(weborb.reader.NamedObject)

Example 7 with BackendlessUser

use of com.backendless.BackendlessUser in project Android-SDK by Backendless.

the class BackendlessUserWriter method write.

@Override
public void write(Object o, IProtocolFormatter iProtocolFormatter) throws IOException {
    BackendlessUser user = (BackendlessUser) o;
    Map<String, Object> props = user.getProperties();
    props.put(Persistence.REST_CLASS_FIELD, UserService.USERS_TABLE_NAME);
    props.put(BackendlessUser.ID_KEY, user.getUserId());
    MessageWriter.writeObject(props, iProtocolFormatter);
}
Also used : BackendlessUser(com.backendless.BackendlessUser)

Example 8 with BackendlessUser

use of com.backendless.BackendlessUser in project Android-SDK by Backendless.

the class BackendlessSerializer method serializeToMap.

public Object serializeToMap(Object entity, Map<Object, Map<String, Object>> serializedCache) {
    if (entity.getClass().isArray())
        return serializeArray(entity, serializedCache);
    if (entity.getClass().isEnum())
        return ((Enum) entity).name();
    Map<String, Object> serializedEntity = new HashMap<String, Object>();
    if (entity.getClass() == BackendlessUser.class)
        serializedEntity = ((BackendlessUser) entity).getProperties();
    else
        weborb.util.ObjectInspector.getObjectProperties(entity.getClass(), entity, (HashMap) serializedEntity, new ArrayList(), true, shouldTraverse());
    serializedCache.put(entity, serializedEntity);
    FootprintsManager.getInstance().Inner.putMissingPropsToEntityMap(entity, serializedEntity);
    // put ___class field, otherwise server will not be able to detect class
    serializedEntity.put(Persistence.REST_CLASS_FIELD, getSimpleName(entity.getClass()));
    // recursively serialize object properties
    Iterator<Map.Entry<String, Object>> entityIterator = serializedEntity.entrySet().iterator();
    while (entityIterator.hasNext()) {
        Map.Entry<String, Object> entityEntry = entityIterator.next();
        // ignoring properties which contain $. This occurs in InstantRun in AndroidStudio - it injects $change property.
        if (entityEntry.getKey().contains("$")) {
            entityIterator.remove();
            continue;
        }
        // http://developer.android.com/reference/android/os/Parcelable.html
        if (Backendless.isAndroid() && entityEntry.getKey().equals(Persistence.PARCELABLE_CREATOR_FIELD_NAME)) {
            entityIterator.remove();
            continue;
        }
        Object entityEntryValue = entityEntry.getValue();
        // ignore null entries and GeoPoints
        if (entityEntryValue == null || entityEntryValue instanceof GeoPoint)
            continue;
        // check for anonymous class entry
        if (entityEntryValue.getClass().isAnonymousClass())
            throw new BackendlessException(String.format(ExceptionMessage.ANONYMOUS_CLASSES_PROHIBITED, entityEntry.getKey()));
        // check if entity entry is collection
        if (entityEntryValue instanceof List) {
            List listEntry = (List) entityEntryValue;
            // empty lists should not be sent to the server
            if (listEntry.isEmpty()) {
                // if there is no object id, remove empty list
                if (!serializedEntity.containsKey(Persistence.DEFAULT_OBJECT_ID_FIELD) || serializedEntity.get(Persistence.DEFAULT_OBJECT_ID_FIELD) == null)
                    entityIterator.remove();
                continue;
            }
            // do nothing with lists of GeoPoints
            if (listEntry.iterator().next() instanceof GeoPoint)
                continue;
            // check for anonymous class entry
            if (listEntry.iterator().next().getClass().isAnonymousClass())
                throw new BackendlessException(String.format(ExceptionMessage.ANONYMOUS_CLASSES_PROHIBITED, entityEntry.getKey()));
            List<Object> newCollection = new ArrayList<Object>();
            for (Object listEntryItem : listEntry) if (!isBelongsJdk(listEntryItem.getClass()))
                newCollection.add(getOrMakeSerializedObject(listEntryItem, serializedCache));
            else
                newCollection.add(listEntryItem);
            entityEntry.setValue(newCollection);
        } else if (entityEntryValue instanceof Object[]) {
            Object[] arrayEntry = (Object[]) entityEntryValue;
            // do nothing with empty arrays and arrays of GeoPoints
            if (arrayEntry.length == 0 || arrayEntry[0] instanceof GeoPoint)
                continue;
            // check for anonymous class entry
            if (arrayEntry[0].getClass().isAnonymousClass())
                throw new BackendlessException(String.format(ExceptionMessage.ANONYMOUS_CLASSES_PROHIBITED, entityEntry.getKey()));
            List<Object> newCollection = new ArrayList<Object>();
            for (Object arrayEntryItem : arrayEntry) if (!isBelongsJdk(arrayEntryItem.getClass()))
                newCollection.add(getOrMakeSerializedObject(arrayEntryItem, serializedCache));
            else
                newCollection.add(arrayEntryItem);
            entityEntry.setValue(newCollection);
        } else // not collection
        {
            if (!isBelongsJdk(entityEntryValue.getClass()))
                entityEntry.setValue(getOrMakeSerializedObject(entityEntryValue, serializedCache));
        }
    }
    return serializedEntity;
}
Also used : BackendlessException(com.backendless.exceptions.BackendlessException) BackendlessUser(com.backendless.BackendlessUser) GeoPoint(com.backendless.geo.GeoPoint)

Example 9 with BackendlessUser

use of com.backendless.BackendlessUser in project Android-SDK by Backendless.

the class LoginActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.act_login);
    Backendless.initApp(LoginActivity.this, Default.APP_ID, Default.SECRET_KEY, Default.VERSION);
    TextView textEmail = (TextView) findViewById(R.id.textEmail);
    TextView textPass = (TextView) findViewById(R.id.textPass);
    TextView textPiar = (TextView) findViewById(R.id.textPiar);
    TextView textOr = (TextView) findViewById(R.id.textOr);
    Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/verdana.ttf");
    textEmail.setTypeface(typeface);
    textPass.setTypeface(typeface);
    textPiar.setTypeface(typeface);
    textOr.setTypeface(typeface);
    final Button loginBtn = (Button) findViewById(R.id.loginBtn);
    loginBtn.setTypeface(typeface);
    loginBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            EditText editEmailText = (EditText) findViewById(R.id.emailEdit);
            EditText editPasswordText = (EditText) findViewById(R.id.passwordEdit);
            final String messageMail = editEmailText.getText().toString();
            final String messagePassword = editPasswordText.getText().toString();
            if (TextUtils.isEmpty(messageMail) || TextUtils.isEmpty(messagePassword)) {
                String alertMessage = "Please, fill in empty fields!";
                Toast.makeText(LoginActivity.this, alertMessage, Toast.LENGTH_LONG).show();
                return;
            }
            progressDialog = ProgressDialog.show(LoginActivity.this, "", "Loading", true);
            Backendless.UserService.login(messageMail, messagePassword, new AsyncCallback<BackendlessUser>() {

                @Override
                public void handleResponse(BackendlessUser backendlessUser) {
                    progressDialog.cancel();
                    Intent intent = new Intent(LoginActivity.this, EndlessTaggingActivity.class);
                    intent.putExtra(Default.EXTRA_EMAIL, messageMail);
                    intent.putExtra(Default.EXTRA_PASSWORD, messagePassword);
                    startActivity(intent);
                }

                @Override
                public void handleFault(BackendlessFault backendlessFault) {
                    progressDialog.cancel();
                    Toast.makeText(LoginActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
                }
            });
        }
    });
    Button goRegistrationBtn = (Button) findViewById(R.id.goRegistrationBtn);
    goRegistrationBtn.setTypeface(typeface);
    goRegistrationBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = new Intent(LoginActivity.this, RegistrationActivity.class);
            startActivity(intent);
            finish();
        }
    });
    Button facebookBtn = (Button) findViewById(R.id.facebookBtn);
    facebookBtn.setTypeface(typeface);
    facebookBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Backendless.UserService.loginWithFacebook(LoginActivity.this, new AsyncCallback<BackendlessUser>() {

                @Override
                public void handleResponse(BackendlessUser response) {
                    Intent intent = new Intent(LoginActivity.this, EndlessTaggingActivity.class);
                    startActivity(intent);
                }

                @Override
                public void handleFault(BackendlessFault fault) {
                    Toast.makeText(LoginActivity.this, fault.getMessage(), Toast.LENGTH_LONG).show();
                }
            });
        }
    });
    Button twitterBtn = (Button) findViewById(R.id.twitterBtn);
    twitterBtn.setTypeface(typeface);
    twitterBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Backendless.UserService.loginWithTwitter(LoginActivity.this, new AsyncCallback<BackendlessUser>() {

                @Override
                public void handleResponse(BackendlessUser response) {
                    Intent intent = new Intent(LoginActivity.this, EndlessTaggingActivity.class);
                    startActivity(intent);
                }

                @Override
                public void handleFault(BackendlessFault fault) {
                    Toast.makeText(LoginActivity.this, fault.getMessage(), Toast.LENGTH_LONG).show();
                }
            });
        }
    });
}
Also used : EditText(android.widget.EditText) BackendlessUser(com.backendless.BackendlessUser) Typeface(android.graphics.Typeface) AsyncCallback(com.backendless.async.callback.AsyncCallback) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) BackendlessFault(com.backendless.exceptions.BackendlessFault) Button(android.widget.Button) TextView(android.widget.TextView)

Example 10 with BackendlessUser

use of com.backendless.BackendlessUser in project Android-SDK by Backendless.

the class RegistrationActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.act_registration);
    TextView textEmail = (TextView) findViewById(R.id.textEmail);
    TextView textPass = (TextView) findViewById(R.id.textPass);
    TextView textName = (TextView) findViewById(R.id.textName);
    TextView textRegistration = (TextView) findViewById(R.id.textRegistration);
    Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/verdana.ttf");
    textEmail.setTypeface(typeface);
    textPass.setTypeface(typeface);
    textName.setTypeface(typeface);
    textRegistration.setTypeface(typeface);
    Button registrationBtn = (Button) findViewById(R.id.registrationBtn);
    registrationBtn.setTypeface(typeface);
    registrationBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            EditText editEmailText = (EditText) findViewById(R.id.emailEdit);
            EditText editPasswordText = (EditText) findViewById(R.id.passwordEdit);
            EditText editNameText = (EditText) findViewById(R.id.editUserName);
            final String messageMail = editEmailText.getText().toString();
            final String messagePassword = editPasswordText.getText().toString();
            final String messageName = editNameText.getText().toString();
            if (TextUtils.isEmpty(messageMail) || TextUtils.isEmpty(messagePassword) || TextUtils.isEmpty(messageName)) {
                String alertMessage = "Please, fill in all fields!";
                Toast.makeText(RegistrationActivity.this, alertMessage, Toast.LENGTH_LONG).show();
                return;
            }
            progressDialog = ProgressDialog.show(RegistrationActivity.this, "", "Loading", true);
            BackendlessUser userObj = new BackendlessUser();
            userObj.setProperty("name", messageName);
            userObj.setEmail(messageMail);
            userObj.setPassword(messagePassword);
            Backendless.UserService.register(userObj, new AsyncCallback<BackendlessUser>() {

                @Override
                public void handleResponse(BackendlessUser backendlessUser) {
                    final Intent intent = new Intent(RegistrationActivity.this, LoginActivity.class);
                    intent.putExtra(Default.EXTRA_PASSWORD, messagePassword);
                    intent.putExtra(Default.EXTRA_EMAIL, messageMail);
                    startActivity(intent);
                    progressDialog.cancel();
                    finish();
                    Toast.makeText(RegistrationActivity.this, "Registration was successful", Toast.LENGTH_LONG).show();
                }

                @Override
                public void handleFault(BackendlessFault backendlessFault) {
                    progressDialog.cancel();
                    Toast.makeText(RegistrationActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
                }
            });
        }
    });
    Button cancelBtn = (Button) findViewById(R.id.cancelBtn);
    cancelBtn.setTypeface(typeface);
    cancelBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = new Intent(RegistrationActivity.this, LoginActivity.class);
            startActivity(intent);
            finish();
        }
    });
}
Also used : EditText(android.widget.EditText) BackendlessUser(com.backendless.BackendlessUser) Typeface(android.graphics.Typeface) AsyncCallback(com.backendless.async.callback.AsyncCallback) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) BackendlessFault(com.backendless.exceptions.BackendlessFault) Button(android.widget.Button) TextView(android.widget.TextView)

Aggregations

BackendlessUser (com.backendless.BackendlessUser)12 View (android.view.View)8 EditText (android.widget.EditText)5 Intent (android.content.Intent)4 Button (android.widget.Button)3 TextView (android.widget.TextView)3 AsyncCallback (com.backendless.async.callback.AsyncCallback)3 BackendlessFault (com.backendless.exceptions.BackendlessFault)3 Typeface (android.graphics.Typeface)2 DatePickerDialog (android.app.DatePickerDialog)1 ArrayAdapter (android.widget.ArrayAdapter)1 DatePicker (android.widget.DatePicker)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 RadioGroup (android.widget.RadioGroup)1 BackendlessCollection (com.backendless.BackendlessCollection)1 BackendlessCallback (com.backendless.async.callback.BackendlessCallback)1 ResponseAsyncCallback (com.backendless.examples.endless.matchmaker.controllers.shared.ResponseAsyncCallback)1 Gender (com.backendless.examples.endless.matchmaker.models.local.Gender)1 Task (com.backendless.examples.userservice.rolesdemo.Task)1