Search in sources :

Example 1 with GeoCategory

use of com.backendless.geo.GeoCategory 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();
                    }
                });
            }
        }
    });
}
Also used : Typeface(android.graphics.Typeface) 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)

Example 2 with GeoCategory

use of com.backendless.geo.GeoCategory 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

Intent (android.content.Intent)2 Typeface (android.graphics.Typeface)2 SparseBooleanArray (android.util.SparseBooleanArray)2 View (android.view.View)2 BackendlessFault (com.backendless.exceptions.BackendlessFault)2 GeoCategory (com.backendless.geo.GeoCategory)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2