use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class AdaptingResponder method responseHandler.
public final void responseHandler(Object adaptingType) {
IAdaptingType type = (IAdaptingType) adaptingType;
IAdaptingType bodyHolder = ((NamedObject) type).getTypedObject();
if (((IAdaptingType) adaptingType).getDefaultType().equals(ErrMessage.class)) {
if (nextResponder != null) {
nextResponder.errorHandler(adaptFault((AnonymousObject) bodyHolder));
}
} else {
IAdaptingType entity = (IAdaptingType) ((AnonymousObject) bodyHolder).getProperties().get("body");
try {
adaptingPolicy.adapt(clazz, entity, nextResponder);
} catch (AdaptingException e) {
errorHandler(new BackendlessFault(e));
}
}
}
use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class EditPreferencesActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.editpreference);
progressDialog = UIFactory.getDefaultProgressDialog(this);
TextView preferenceName = (TextView) findViewById(R.id.preferenceName);
preferencesContainer = (LinearLayout) findViewById(R.id.preferencesContainer);
preferenceTheme = PreferenceTheme.valueOf(getIntent().getStringExtra(Lifecycle.PREFERENCE_TYPE_TAG));
preferenceStore = Backendless.Persistence.of(UserPreferences.class);
// Naming the page
preferenceName.setText(preferenceTheme.getPreference());
((TextView) findViewById(R.id.preferenceLabel)).setText(getString(R.string.textfield_preferences_label_base) + " " + preferenceTheme.getPreference().toLowerCase() + ":");
// Getting preference structure
BackendlessDataQuery backendlessDataQuery = new BackendlessDataQuery("theme = '" + preferenceTheme.getPreference() + "'");
QueryOptions queryOptions = new QueryOptions();
queryOptions.setPageSize(50);
queryOptions.addSortByOption("name");
backendlessDataQuery.setQueryOptions(queryOptions);
Backendless.Persistence.of(PreferencesDefaults.class).find(backendlessDataQuery, new AsyncCallback<Collection<PreferencesDefaults>>() {
@Override
public void handleResponse(Collection<PreferencesDefaults> preferencesDefaultsBackendlessCollection) {
// Creating a map with predefined checkboxes
List<PreferencesDefaults> preferencesDefaults = preferencesDefaultsBackendlessCollection.getCurrentPage();
for (PreferencesDefaults preference : preferencesDefaults) {
CheckBox checkBox = UIFactory.getPreferenceCheckbox(EditPreferencesActivity.this, preference);
checkBox.setOnClickListener(getCheckboxListener(checkBox));
preferencesContainer.addView(checkBox);
preferenceNameToCheckboxMap.put(preference.getName(), checkBox);
}
// Getting preferences, which should be enabled for current user
String whereClause = "email = '" + Backendless.UserService.CurrentUser().getEmail() + "'";
whereClause += " and theme = '" + preferenceTheme.getPreference() + "'";
BackendlessDataQuery backendlessDataQuery = new BackendlessDataQuery();
backendlessDataQuery.setWhereClause(whereClause);
backendlessDataQuery.setQueryOptions(new QueryOptions(50, 0));
Backendless.Persistence.of(UserPreferences.class).find(backendlessDataQuery, new AsyncCallback<Collection<UserPreferences>>() {
@Override
public void handleResponse(Collection<UserPreferences> userPreferencesBackendlessCollection) {
List<UserPreferences> userPreferences = userPreferencesBackendlessCollection.getCurrentPage();
for (UserPreferences userPreference : userPreferences) {
CheckBox checkBox = preferenceNameToCheckboxMap.get(userPreference.getPreference());
preferenceNameToPreferenceMap.put(userPreference.getPreference(), userPreference);
checkBox.setChecked(true);
}
progressDialog.cancel();
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
progressDialog.cancel();
Toast.makeText(EditPreferencesActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
progressDialog.cancel();
Toast.makeText(EditPreferencesActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class FindMatchesActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.findmatches);
adapter = new PointsAdapter(FindMatchesActivity.this);
MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
googleMap = mapFragment.getMap();
googleMap.setMyLocationEnabled(true);
progressDialog = UIFactory.getDefaultProgressDialog(this);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
matchesFound = (TextView) findViewById(R.id.matchesFound);
matchesFound.setText("0");
textFoundGlobal = (TextView) findViewById(R.id.textFoundGlobal);
textFoundGlobal.setText("0");
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setPowerRequirement(Criteria.POWER_LOW);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setSpeedRequired(false);
criteria.setCostAllowed(true);
boolean enabledGPS = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (!enabledGPS)
Toast.makeText(FindMatchesActivity.this, "No GPS signal", Toast.LENGTH_LONG).show();
boolean networkIsEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!networkIsEnabled)
Toast.makeText(FindMatchesActivity.this, "No Network signal", Toast.LENGTH_LONG).show();
String provider = locationManager.getBestProvider(criteria, true);
LocationListener myLocationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
if (location == null)
Toast.makeText(FindMatchesActivity.this, "Location unknown", Toast.LENGTH_LONG).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void onProviderEnabled(String provider) {
// To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void onProviderDisabled(String provider) {
// To change body of implemented methods use File | Settings | File Templates.
}
};
Location location = locationManager.getLastKnownLocation(provider);
locationManager.requestSingleUpdate(criteria, myLocationListener, null);
if (provider == null) {
UIFactory.getLocationSettingsDialog(this).show();
finish();
}
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
myLocation = new GeoPoint(latitude, longitude);
myPosition = new LatLng(latitude, longitude);
SharedPreferences settings = getSharedPreferences(PREF_TAG, 0);
String email = settings.getString(EMAIL_PREF, null);
BackendlessGeoQuery backendlessGeoQuery = new BackendlessGeoQuery(BackendlessUser.EMAIL_KEY, email);
Backendless.Geo.getPoints(backendlessGeoQuery, gotCurrentUserGeoPointCallback);
BackendlessGeoQuery backendlessGeoQueryGlobal = new BackendlessGeoQuery();
Backendless.Geo.getPoints(backendlessGeoQueryGlobal, new AsyncCallback<Collection<GeoPoint>>() {
@Override
public void handleResponse(Collection<GeoPoint> geoPointBackendlessCollection) {
List<GeoPoint> geoPoints = geoPointBackendlessCollection.getCurrentPage();
if (!geoPoints.isEmpty())
textFoundGlobal.setText(String.valueOf(geoPoints.size() - 1));
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
Toast.makeText(FindMatchesActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
}
});
} else
Toast.makeText(FindMatchesActivity.this, "Can't determine your location. Check the settings your device and restart the application.", Toast.LENGTH_LONG).show();
googleMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View view = getLayoutInflater().inflate(R.layout.custom_info_window, null);
ImageView imageView = (ImageView) view.findViewById(R.id.imagePhoto);
if (bitmapToMarkerMap.containsKey(marker))
imageView.setImageBitmap(bitmapToMarkerMap.get(marker));
TextView title = (TextView) view.findViewById(R.id.textTitlePoint);
title.setText(marker.getTitle());
TextView sniped = (TextView) view.findViewById(R.id.textSnipedPoint);
sniped.setText(marker.getSnippet());
imageView.setImageResource(sniped.getText().equals("male") ? R.drawable.avatar_default_male : R.drawable.avatar_default_female);
return view;
}
});
googleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
for (int i = 0; i < adapter.pointsList.size(); i++) {
GeoPoint pointData = adapter.pointsList.get(i);
Map<String, String> newMetaData = pointData.getMetadata();
String pointName = newMetaData.get(Defaults.NAME_PROPERTY);
if (pointName.equals(marker.getTitle()))
Lifecycle.runMatchViewActivity(FindMatchesActivity.this, myLocation, pointData);
}
}
});
googleMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition cameraPosition) {
LatLngBounds visibleRegion = googleMap.getProjection().getVisibleRegion().latLngBounds;
LatLng topRight = visibleRegion.northeast;
LatLng botDown = visibleRegion.southwest;
SWLat = botDown.latitude;
SWLon = botDown.longitude;
NELat = topRight.latitude;
NELon = topRight.longitude;
findMatches();
}
});
findViewById(R.id.profileButton).setOnClickListener(profileListener);
findViewById(R.id.pingsButton).setOnClickListener(pingsListener);
}
use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class ProfileActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.profile);
TextView nameField = (TextView) findViewById(R.id.nameField);
TextView genderField = (TextView) findViewById(R.id.genderField);
TextView ageField = (TextView) findViewById(R.id.ageField);
ImageView avatarImage = (ImageView) findViewById(R.id.avatarImage);
ImageView genderImage = (ImageView) findViewById(R.id.genderImage);
BackendlessUser currentUser = Backendless.UserService.CurrentUser();
// Checking CurrentUser
if (currentUser == null) {
Lifecycle.runLoginActivity(ProfileActivity.this);
finish();
} else {
nameField.setText((String) currentUser.getProperty(Defaults.NAME_PROPERTY));
Gender userGender = Gender.valueOf((String) currentUser.getProperty(Defaults.GENDER_PROPERTY));
genderField.setText(userGender.toString());
if (userGender == Gender.male) {
avatarImage.setImageDrawable(getResources().getDrawable(R.drawable.avatar_default_male));
genderImage.setImageDrawable(getResources().getDrawable(R.drawable.icon_male));
} else {
avatarImage.setImageDrawable(getResources().getDrawable(R.drawable.avatar_default_female));
genderImage.setImageDrawable(getResources().getDrawable(R.drawable.icon_female));
}
Date birthDate = (Date) currentUser.getProperty(Defaults.BIRTH_DATE_PROPERTY);
ageField.setText(String.valueOf(SimpleMath.getAgeFromDate(birthDate)));
}
findViewById(R.id.findButton).setOnClickListener(findMatchesListener);
findViewById(R.id.editFoodPreferenceButton).setOnClickListener(getEditPreferencesListener(PreferenceTheme.FOOD));
findViewById(R.id.editMusicPreferenceButton).setOnClickListener(getEditPreferencesListener(PreferenceTheme.MUSIC));
findViewById(R.id.editHobbiesPreferenceButton).setOnClickListener(getEditPreferencesListener(PreferenceTheme.HOBBIES));
findViewById(R.id.editTravelPreferenceButton).setOnClickListener(getEditPreferencesListener(PreferenceTheme.TRAVEL));
Button button_logout = (Button) findViewById(R.id.buttonLogOut);
button_logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
progressDialog = UIFactory.getDefaultProgressDialog(ProfileActivity.this);
Backendless.UserService.logout(new AsyncCallback<Void>() {
@Override
public void handleResponse(Void aVoid) {
Lifecycle.runLoginActivity(ProfileActivity.this);
finish();
progressDialog.cancel();
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
progressDialog.cancel();
Toast.makeText(ProfileActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
});
}
use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.
the class CreateNewCategoryActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_new_category);
TextView textCat = (TextView) findViewById(R.id.textCat);
TextView textCategory = (TextView) findViewById(R.id.textCategory);
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/verdana.ttf");
textCat.setTypeface(typeface);
textCategory.setTypeface(typeface);
progressDialog = ProgressDialog.show(CreateNewCategoryActivity.this, "", "Loading", true);
Backendless.Geo.getCategories(new AsyncCallback<List<GeoCategory>>() {
@Override
public void handleResponse(List<GeoCategory> geoCategories) {
List<GeoCategory> categories = geoCategories;
for (GeoCategory category : categories) categoriesNames.add(category.getName());
lvMain = (ListView) findViewById(R.id.lvMain);
lvMain.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(CreateNewCategoryActivity.this, android.R.layout.simple_list_item_multiple_choice, categoriesNames);
lvMain.setAdapter(adapter);
progressDialog.cancel();
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
progressDialog.cancel();
Toast.makeText(CreateNewCategoryActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
}
});
Button addCategoryBtn = (Button) findViewById(R.id.addCategoryBtn);
addCategoryBtn.setTypeface(typeface);
addCategoryBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText addNewCategory = (EditText) findViewById(R.id.editNewCategory);
final String categoryCreateName = addNewCategory.getText().toString();
SparseBooleanArray sbArray = lvMain.getCheckedItemPositions();
List<String> searchCategories = new ArrayList<String>();
for (int i = 0; i < sbArray.size(); i++) {
int key = sbArray.keyAt(i);
if (sbArray.get(key)) {
searchCategories.add(categoriesNames.get(key));
}
}
array = new String[searchCategories.size()];
array = searchCategories.toArray(array);
if (TextUtils.isEmpty(categoryCreateName) && searchCategories.isEmpty()) {
String alertMessage = "Please, fill in empty field or choose category!";
Toast.makeText(CreateNewCategoryActivity.this, alertMessage, Toast.LENGTH_LONG).show();
return;
} else if (categoryCreateName != null && searchCategories.isEmpty()) {
progressDialog = ProgressDialog.show(CreateNewCategoryActivity.this, "", "Loading", true);
Backendless.Geo.addCategory(categoryCreateName, new AsyncCallback<GeoCategory>() {
@Override
public void handleResponse(GeoCategory geoCategory) {
Intent intent = new Intent(CreateNewCategoryActivity.this, AddCommentActivity.class);
intent.putExtra(Default.NEW_CATEGORY_NAME, categoryCreateName);
intent.putExtra(Default.CATEGORY_TRIGER, "1");
setResult(Default.ADD_NEW_CATEGORY_RESULT, intent);
progressDialog.cancel();
finish();
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
progressDialog.cancel();
Toast.makeText(CreateNewCategoryActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
}
});
} else if (TextUtils.isEmpty(categoryCreateName) && !searchCategories.isEmpty()) {
progressDialog = ProgressDialog.show(CreateNewCategoryActivity.this, "", "Loading", true);
Intent intent = new Intent(CreateNewCategoryActivity.this, AddCommentActivity.class);
intent.putExtra(Default.SEARCH_CATEGORY_NAME, array);
intent.putExtra(Default.CATEGORY_TRIGER, "2");
setResult(Default.ADD_NEW_CATEGORY_RESULT, intent);
progressDialog.cancel();
finish();
} else if (categoryCreateName != null && !searchCategories.isEmpty()) {
progressDialog = ProgressDialog.show(CreateNewCategoryActivity.this, "", "Loading", true);
Backendless.Geo.addCategory(categoryCreateName, new AsyncCallback<GeoCategory>() {
@Override
public void handleResponse(GeoCategory geoCategory) {
Intent intent = new Intent(CreateNewCategoryActivity.this, AddCommentActivity.class);
intent.putExtra(Default.NEW_CATEGORY_NAME, categoryCreateName);
intent.putExtra(Default.SEARCH_CATEGORY_NAME, array);
intent.putExtra(Default.CATEGORY_TRIGER, "3");
setResult(Default.ADD_NEW_CATEGORY_RESULT, intent);
progressDialog.cancel();
finish();
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
progressDialog.cancel();
Toast.makeText(CreateNewCategoryActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
}
});
}
Aggregations