Search in sources :

Example 61 with BackendlessFault

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

the class Main method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Defaults.APPLICATION_ID.equals("") || Defaults.SECRET_KEY.equals("") || Defaults.VERSION.equals("")) {
        showAlert(this, "Missing application ID and secret key arguments. Login to Backendless Console, select your app and get the ID and key from the Manage > App Settings screen. Copy/paste the values into the Backendless.initApp call");
        return;
    }
    Backendless.initApp(this, Defaults.APPLICATION_ID, Defaults.SECRET_KEY, Defaults.VERSION);
    ListView listView = getListView();
    listView.addHeaderView(getLayoutInflater().inflate(R.layout.header, null), null, false);
    listView.addFooterView(getLayoutInflater().inflate(R.layout.footer, null), null, false);
    listView.setFooterDividersEnabled(true);
    itemsToDoField = (TextView) findViewById(R.id.itemsToDoField);
    itemsDoneField = (TextView) findViewById(R.id.itemsDoneField);
    final TasksList tasksList = new TasksList(new TasksList.Listener() {

        @Override
        public void onLeftEntitiesChanged(int entitiesCount) {
            itemsToDoField.setText(entitiesCount == 0 ? "" : entitiesCount + " items left");
        }

        @Override
        public void onDoneEntitiesChanged(int entitiesCount) {
            itemsDoneField.setText(entitiesCount == 0 ? "" : "Clear " + entitiesCount + " completed items");
        }
    });
    final TasksAdapter adapter = new TasksAdapter(this, new ArrayList<Task>(), tasksList);
    itemsDoneField.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            adapter.removeAll(tasksList.getDoneEntities());
        }
    });
    setListAdapter(adapter);
    TasksManager.findEntities(new AsyncCallback<List<Task>>() {

        @Override
        public void handleResponse(List<Task> response) {
            adapter.addAll(response);
        }

        @Override
        public void handleFault(BackendlessFault fault) {
        }
    });
    final EditText addToDoField = (EditText) findViewById(R.id.addToDoField);
    addToDoField.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if (keyCode == KeyEvent.KEYCODE_ENTER && keyEvent.getAction() == KeyEvent.ACTION_UP) {
                String message = addToDoField.getText().toString();
                if (message == null || message.equals(""))
                    return true;
                Task task = new Task();
                task.setDeviceId(Messaging.DEVICE_ID);
                task.setTitle(message);
                TasksManager.saveEntity(task, Main.this, new InnerCallback<Task>() {

                    @Override
                    public void handleResponse(Task response) {
                        adapter.add(response);
                        addToDoField.setText("");
                    }
                });
                return true;
            }
            return false;
        }
    });
}
Also used : EditText(android.widget.EditText) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView) BackendlessFault(com.backendless.exceptions.BackendlessFault) KeyEvent(android.view.KeyEvent) ListView(android.widget.ListView) ArrayList(java.util.ArrayList) List(java.util.List)

Example 62 with BackendlessFault

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

the class DialogMessageActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.dialog_message);
    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.mainLay);
    linearLayout.setVisibility(View.GONE);
    Intent intent = getIntent();
    currentName = intent.getStringExtra(Defaults.CURRENT_USER_NAME);
    targetName = intent.getStringExtra(Defaults.TARGET_USER_NAME);
    type = intent.getStringExtra("type");
    progressDialog = UIFactory.getDefaultProgressDialog(this);
    BackendlessGeoQuery backendlessGeoQuery = new BackendlessGeoQuery(BackendlessUser.EMAIL_KEY, Backendless.UserService.CurrentUser().getEmail());
    Backendless.Geo.getPoints(backendlessGeoQuery, new AsyncCallback<Collection<GeoPoint>>() {

        @Override
        public void handleResponse(Collection<GeoPoint> response) {
            List<GeoPoint> points = response.getCurrentPage();
            if (!points.isEmpty()) {
                myLocation = points.get(0);
            }
            if (type.equals("ping")) {
                titleMessage = "New ping!";
                sendMessage = "You were pinged by " + currentName;
            } else {
                titleMessage = "New message!";
                sendMessage = "You got a new message from " + currentName;
            }
            LayoutInflater layoutInflater = getLayoutInflater();
            View checkBoxView = layoutInflater.inflate(R.layout.dialog_message, null);
            final CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.checkBox);
            progressDialog.cancel();
            AlertDialog.Builder builder = new AlertDialog.Builder(DialogMessageActivity.this);
            builder.setTitle(titleMessage);
            builder.setMessage(sendMessage);
            builder.setView(checkBoxView);
            builder.setCancelable(false);
            builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    checkBoxResult = "NOT checked";
                    if (checkBox.isChecked())
                        checkBoxResult = "checked";
                    myLocation.putMetadata(currentName, checkBoxResult);
                    Backendless.Geo.savePoint(myLocation, new AsyncCallback<GeoPoint>() {

                        @Override
                        public void handleResponse(GeoPoint geoPoint) {
                        // Toast.makeText( DialogMessageActivity.this, "Changes successfully saved", Toast.LENGTH_LONG ).show();
                        }

                        @Override
                        public void handleFault(BackendlessFault backendlessFault) {
                            Toast.makeText(DialogMessageActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
                        }
                    });
                    dialog.dismiss();
                    finish();
                }
            });
            if (myLocation.getMetadata(currentName) == null || !myLocation.getMetadata(currentName).equals("checked")) {
                AlertDialog dialog = builder.create();
                dialog.show();
            } else
                finish();
        }

        @Override
        public void handleFault(BackendlessFault fault) {
            Toast.makeText(DialogMessageActivity.this, fault.getMessage(), Toast.LENGTH_LONG).show();
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) BackendlessGeoQuery(com.backendless.geo.BackendlessGeoQuery) View(android.view.View) BackendlessFault(com.backendless.exceptions.BackendlessFault) GeoPoint(com.backendless.geo.GeoPoint) LayoutInflater(android.view.LayoutInflater) BackendlessCollection(com.backendless.BackendlessCollection) List(java.util.List)

Example 63 with BackendlessFault

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

the class EndlessTaggingActivity method searchRectanglePoints.

private void searchRectanglePoints(List<String> categoriesNames) {
    final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
    final TextView textView = (TextView) findViewById(R.id.textLoading);
    textView.setVisibility(TextView.VISIBLE);
    progressBar.setVisibility(ProgressBar.VISIBLE);
    backendlessGeoQuery = new BackendlessGeoQuery();
    backendlessGeoQuery.setSearchRectangle(new double[] { NELat, SWLon, SWLat, NELon });
    backendlessGeoQuery.setCategories(categoriesNames);
    Backendless.Geo.getPoints(backendlessGeoQuery, new AsyncCallback<Collection<GeoPoint>>() {

        @Override
        public void handleResponse(Collection<GeoPoint> geoPointBackendlessCollection) {
            List<GeoPoint> points = geoPointBackendlessCollection.getCurrentPage();
            double newLatitude, newLongitude;
            adapter.clear();
            if (!points.isEmpty())
                adapter.addAll(points);
            adapter.notifyDataSetChanged();
            for (GeoPoint point : points) {
                newLatitude = point.getLatitude();
                newLongitude = point.getLongitude();
                Map<String, String> newMetaData = point.getMetadata();
                String endlessTagging = newMetaData.get("endlessTagging");
                if (endlessTagging != null) {
                    String pointName = newMetaData.get("pointName");
                    String pointDescription = newMetaData.get("pointDescription");
                    LatLng newPosition = new LatLng(newLatitude, newLongitude);
                    googleMap.addMarker(new MarkerOptions().position(newPosition).title(pointName).snippet(pointDescription).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_blue)));
                }
            }
            textView.setVisibility(TextView.INVISIBLE);
            progressBar.setVisibility(ProgressBar.INVISIBLE);
        }

        @Override
        public void handleFault(BackendlessFault backendlessFault) {
            textView.setVisibility(TextView.INVISIBLE);
            progressBar.setVisibility(ProgressBar.INVISIBLE);
            Toast.makeText(EndlessTaggingActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
        }
    });
}
Also used : BackendlessGeoQuery(com.backendless.geo.BackendlessGeoQuery) BackendlessFault(com.backendless.exceptions.BackendlessFault) GeoPoint(com.backendless.geo.GeoPoint) BackendlessCollection(com.backendless.BackendlessCollection) GoogleMap(com.google.android.gms.maps.GoogleMap)

Example 64 with BackendlessFault

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

the class EndlessTaggingActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (data == null)
        return;
    switch(requestCode) {
        case Default.CATEGORY_RESULT_SEARCH:
            googleMap.clear();
            googleMap.addMarker(new MarkerOptions().position(myPosition).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_red)));
            List<String> searchCategory = Arrays.asList(data.getStringArrayExtra(Default.SEARCH_CATEGORY_NAME));
            selectedCategories = new ArrayList<String>();
            selectedCategories = searchCategory;
            searchRectanglePoints(selectedCategories.isEmpty() ? categoriesNames : selectedCategories);
            break;
        case Default.ADD_NEW_CATEGORY_RESULT:
            String categoryTriger = data.getStringExtra(Default.CATEGORY_TRIGER);
            if (categoryTriger.equals("1"))
                category = data.getStringExtra(Default.NEW_CATEGORY_NAME);
            if (categoryTriger.equals("2"))
                pointCategories = Arrays.asList(data.getStringArrayExtra(Default.SEARCH_CATEGORY_NAME));
            if (categoryTriger.equals("3")) {
                category = data.getStringExtra(Default.NEW_CATEGORY_NAME);
                pointCategories = Arrays.asList(data.getStringArrayExtra(Default.SEARCH_CATEGORY_NAME));
            }
            Intent intentComment = new Intent(EndlessTaggingActivity.this, AddCommentActivity.class);
            intentComment.putExtra(Default.FILE_PATH, filePath);
            startActivityForResult(intentComment, Default.ADD_NEW_POINT_RESULT);
            break;
        case Default.ADD_NEW_POINT_RESULT:
            pointNameNew = data.getStringExtra(Default.NEW_POINT_NAME);
            googleMap.clear();
            if (category != null && pointCategories.isEmpty()) {
                AlertDialog.Builder builder = new AlertDialog.Builder(EndlessTaggingActivity.this);
                builder.setMessage(R.string.save_data);
                builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        List<String> categories = new ArrayList<String>();
                        categories.add(category);
                        Map<String, String> metadata = new HashMap<String, String>();
                        metadata.put("pointName", pointNameNew);
                        metadata.put("pointDescription", category);
                        metadata.put("photoUrl", photoUrl);
                        metadata.put("endlessTagging", "true");
                        if (onMapClick) {
                            latitude = latitudeOnMap;
                            longitude = longitudeOnMap;
                        }
                        GeoPoint geoPoint = new GeoPoint(latitude, longitude, categories, metadata);
                        progressDialog = ProgressDialog.show(EndlessTaggingActivity.this, "", "Loading", true);
                        Backendless.Geo.savePoint(geoPoint, new AsyncCallback<GeoPoint>() {

                            @Override
                            public void handleResponse(GeoPoint geoPoint) {
                                adapter.add(geoPoint);
                                progressDialog.cancel();
                                selectedCategories = new ArrayList<String>();
                                selectedCategories.add(category);
                                searchRectanglePoints(selectedCategories.isEmpty() ? categoriesNames : selectedCategories);
                            }

                            @Override
                            public void handleFault(BackendlessFault backendlessFault) {
                                progressDialog.cancel();
                                Toast.makeText(EndlessTaggingActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
                            }
                        });
                    }
                });
                builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(EndlessTaggingActivity.this, AddCommentActivity.class);
                        startActivity(intent);
                        finish();
                    }
                });
                AlertDialog dialog = builder.create();
                dialog.show();
            } else if (category == null && !pointCategories.isEmpty()) {
                AlertDialog.Builder builder = new AlertDialog.Builder(EndlessTaggingActivity.this);
                builder.setMessage(R.string.save_data);
                builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        List<String> categories = new ArrayList<String>();
                        categories.addAll(pointCategories);
                        StringBuilder result = new StringBuilder();
                        for (int i = 0; i < pointCategories.size(); i++) {
                            result.append(pointCategories.get(i));
                            if (i < pointCategories.size() - 1)
                                result.append(", ");
                        }
                        categoryInLine = result.toString();
                        Map<String, String> metadata = new HashMap<String, String>();
                        metadata.put("pointName", pointNameNew);
                        metadata.put("pointDescription", categoryInLine);
                        metadata.put("photoUrl", photoUrl);
                        metadata.put("endlessTagging", "true");
                        if (onMapClick) {
                            latitude = latitudeOnMap;
                            longitude = longitudeOnMap;
                        }
                        GeoPoint geoPoint = new GeoPoint(latitude, longitude, categories, metadata);
                        progressDialog = ProgressDialog.show(EndlessTaggingActivity.this, "", "Loading", true);
                        Backendless.Geo.savePoint(geoPoint, new AsyncCallback<GeoPoint>() {

                            @Override
                            public void handleResponse(GeoPoint geoPoint) {
                                adapter.add(geoPoint);
                                selectedCategories = new ArrayList<String>();
                                selectedCategories.addAll(pointCategories);
                                searchRectanglePoints(selectedCategories.isEmpty() ? categoriesNames : selectedCategories);
                                progressDialog.cancel();
                            }

                            @Override
                            public void handleFault(BackendlessFault backendlessFault) {
                                progressDialog.cancel();
                                Toast.makeText(EndlessTaggingActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
                            }
                        });
                    }
                });
                builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(EndlessTaggingActivity.this, AddCommentActivity.class);
                        startActivity(intent);
                        finish();
                    }
                });
                AlertDialog dialog = builder.create();
                dialog.show();
            } else if (category != null && !pointCategories.isEmpty()) {
                AlertDialog.Builder builder = new AlertDialog.Builder(EndlessTaggingActivity.this);
                builder.setMessage(R.string.save_data);
                builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        List<String> categories = new ArrayList<String>();
                        categories.add(category);
                        categories.addAll(pointCategories);
                        StringBuilder result = new StringBuilder();
                        for (int i = 0; i < categories.size(); i++) {
                            result.append(categories.get(i));
                            if (i < categories.size() - 1)
                                result.append(", ");
                        }
                        categoryInLine = result.toString();
                        Map<String, String> metadata = new HashMap<String, String>();
                        metadata.put("pointName", pointNameNew);
                        metadata.put("pointDescription", categoryInLine);
                        metadata.put("photoUrl", photoUrl);
                        metadata.put("endlessTagging", "true");
                        if (onMapClick) {
                            latitude = latitudeOnMap;
                            longitude = longitudeOnMap;
                        }
                        GeoPoint geoPoint = new GeoPoint(latitude, longitude, categories, metadata);
                        progressDialog = ProgressDialog.show(EndlessTaggingActivity.this, "", "Loading", true);
                        Backendless.Geo.savePoint(geoPoint, new AsyncCallback<GeoPoint>() {

                            @Override
                            public void handleResponse(GeoPoint geoPoint) {
                                adapter.add(geoPoint);
                                progressDialog.cancel();
                                selectedCategories = new ArrayList<String>();
                                selectedCategories.add(category);
                                selectedCategories.addAll(pointCategories);
                                searchRectanglePoints(selectedCategories.isEmpty() ? categoriesNames : selectedCategories);
                            }

                            @Override
                            public void handleFault(BackendlessFault backendlessFault) {
                                progressDialog.cancel();
                                Toast.makeText(EndlessTaggingActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
                            }
                        });
                    }
                });
                builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(EndlessTaggingActivity.this, AddCommentActivity.class);
                        startActivity(intent);
                        finish();
                    }
                });
                AlertDialog dialog = builder.create();
                dialog.show();
            }
            break;
        case Default.ADD_NEW_COMMENT:
            googleMap.clear();
            googleMap.addMarker(new MarkerOptions().position(myPosition).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_red)));
            String nameCategory = data.getStringExtra(Default.SEARCH_CATEGORY_NAME);
            selectedCategories = new ArrayList<String>();
            selectedCategories.add(nameCategory);
            searchRectanglePoints(selectedCategories.isEmpty() ? categoriesNames : selectedCategories);
            break;
        case Default.ADD_NEW_PHOTO_RESULT:
            photoUrl = data.getStringExtra(Default.PHOTO_CAMERA_URL);
            if (photoUrl == null)
                photoUrl = data.getStringExtra(Default.PHOTO_BROWSE_URL);
            filePath = data.getStringExtra(Default.FILE_PATH);
            Intent intent = new Intent(EndlessTaggingActivity.this, CreateNewCategoryActivity.class);
            startActivityForResult(intent, Default.ADD_NEW_CATEGORY_RESULT);
            break;
        default:
            break;
    }
}
Also used : DialogInterface(android.content.DialogInterface) AsyncCallback(com.backendless.async.callback.AsyncCallback) GeoPoint(com.backendless.geo.GeoPoint) Intent(android.content.Intent) GeoPoint(com.backendless.geo.GeoPoint) BackendlessFault(com.backendless.exceptions.BackendlessFault) GoogleMap(com.google.android.gms.maps.GoogleMap)

Example 65 with BackendlessFault

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

the class FilterActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.act_filter);
    TextView textEndless = (TextView) findViewById(R.id.textFilter);
    final Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/verdana.ttf");
    textEndless.setTypeface(typeface);
    progressDialog = ProgressDialog.show(FilterActivity.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());
            listView = (ListView) findViewById(R.id.lvMain);
            listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(FilterActivity.this, android.R.layout.simple_list_item_multiple_choice, categoriesNames);
            listView.setAdapter(adapter);
            progressDialog.cancel();
            Button searchBtnMulti = (Button) findViewById(R.id.searchBtnMulti);
            searchBtnMulti.setTypeface(typeface);
            searchBtnMulti.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    progressDialog = ProgressDialog.show(FilterActivity.this, "", "Loading", true);
                    SparseBooleanArray sbArray = listView.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));
                        }
                    }
                    String[] array = new String[searchCategories.size()];
                    array = searchCategories.toArray(array);
                    Intent intent = new Intent();
                    intent.putExtra(Default.SEARCH_CATEGORY_NAME, array);
                    setResult(Default.CATEGORY_RESULT_SEARCH, intent);
                    progressDialog.cancel();
                    finish();
                }
            });
            Intent intent = getIntent();
            if (intent.getExtras() != null) {
                List<String> searchCheckBox = Arrays.asList(intent.getStringArrayExtra(Default.SEARCH_CHECK_BOX));
                SparseBooleanArray checkedStates = listView.getCheckedItemPositions();
                for (String element : searchCheckBox) {
                    int position = adapter.getPosition(element);
                    checkedStates.put(position, true);
                }
            }
        }

        @Override
        public void handleFault(BackendlessFault backendlessFault) {
            progressDialog.cancel();
            Toast.makeText(FilterActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
        }
    });
}
Also used : Typeface(android.graphics.Typeface) ArrayList(java.util.ArrayList) Intent(android.content.Intent) View(android.view.View) BackendlessFault(com.backendless.exceptions.BackendlessFault) SparseBooleanArray(android.util.SparseBooleanArray) ArrayList(java.util.ArrayList) List(java.util.List) GeoCategory(com.backendless.geo.GeoCategory)

Aggregations

BackendlessFault (com.backendless.exceptions.BackendlessFault)65 AnonymousObject (weborb.reader.AnonymousObject)15 NamedObject (weborb.reader.NamedObject)15 AsyncCallback (com.backendless.async.callback.AsyncCallback)11 Intent (android.content.Intent)10 View (android.view.View)10 TextView (android.widget.TextView)6 BackendlessCollection (com.backendless.BackendlessCollection)6 List (java.util.List)6 Typeface (android.graphics.Typeface)5 BackendlessDataQuery (com.backendless.persistence.BackendlessDataQuery)5 EditText (android.widget.EditText)4 CollectionAdaptingPolicy (com.backendless.core.responder.policy.CollectionAdaptingPolicy)4 BackendlessFile (com.backendless.files.BackendlessFile)4 ArrayList (java.util.ArrayList)4 Button (android.widget.Button)3 GeoPoint (com.backendless.geo.GeoPoint)3 ProgressDialog (android.app.ProgressDialog)2 DialogInterface (android.content.DialogInterface)2 Bitmap (android.graphics.Bitmap)2