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();
}
});
}
}
});
}
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();
}
});
}
Aggregations