use of android.support.design.widget.Snackbar in project Remindy by abicelis.
the class PlaceActivity method handleSaveOrUpdatePlace.
private void handleSaveOrUpdatePlace() {
BaseTransientBottomBar.BaseCallback<Snackbar> callback = new BaseTransientBottomBar.BaseCallback<Snackbar>() {
@Override
public void onDismissed(Snackbar transientBottomBar, int event) {
super.onDismissed(transientBottomBar, event);
setResult(RESULT_OK);
finish();
}
};
mDao = new RemindyDAO(getApplicationContext());
//Verify mPlace is set
if (mPlace.getLongitude() == 0) {
SnackbarUtil.showSnackbar(mMapContainer, SnackbarUtil.SnackbarType.ERROR, R.string.activity_place_snackbar_error_no_place, SnackbarUtil.SnackbarDuration.LONG, null);
return;
}
if (mPlace.getAlias() == null || mPlace.getAlias().isEmpty() || mPlace.getAlias().equals(getResources().getString(R.string.activity_place_alias_hint))) {
SnackbarUtil.showSnackbar(mMapContainer, SnackbarUtil.SnackbarType.NOTICE, R.string.activity_place_snackbar_error_no_alias, SnackbarUtil.SnackbarDuration.LONG, null);
return;
}
if (mPlaceToEdit != null) {
try {
mDao.updatePlace(mPlace);
//Update geofences when updating places!
GeofenceUtil.updateGeofences(getApplicationContext(), mGoogleApiClient);
SnackbarUtil.showSnackbar(mMapContainer, SnackbarUtil.SnackbarType.SUCCESS, R.string.activity_place_snackbar_edit_succesful, SnackbarUtil.SnackbarDuration.SHORT, callback);
} catch (CouldNotUpdateDataException e) {
SnackbarUtil.showSnackbar(mMapContainer, SnackbarUtil.SnackbarType.ERROR, R.string.activity_place_snackbar_error_saving, SnackbarUtil.SnackbarDuration.LONG, null);
}
} else {
try {
mDao.insertPlace(mPlace);
SnackbarUtil.showSnackbar(mMapContainer, SnackbarUtil.SnackbarType.SUCCESS, R.string.activity_place_snackbar_save_succesful, SnackbarUtil.SnackbarDuration.SHORT, callback);
} catch (CouldNotInsertDataException e) {
SnackbarUtil.showSnackbar(mMapContainer, SnackbarUtil.SnackbarType.ERROR, R.string.activity_place_snackbar_error_saving, SnackbarUtil.SnackbarDuration.LONG, null);
}
}
}
use of android.support.design.widget.Snackbar in project Remindy by abicelis.
the class TaskActivity method handleTaskSave.
private void handleTaskSave() {
AttachmentUtil.cleanInvalidAttachments(mTask.getAttachments());
try {
RemindyDAO dao = new RemindyDAO(this);
if (!editingTask) {
//Insert the task
dao.insertTask(mTask);
//Update geofences
if (mTask.getReminderType().equals(ReminderType.LOCATION_BASED))
GeofenceUtil.updateGeofences(getApplicationContext(), mGoogleApiClient);
//Update alarms
if (mTask.getReminderType().equals(ReminderType.ONE_TIME) || mTask.getReminderType().equals(ReminderType.REPEATING)) {
//Remove task from triggeredTasks list
SharedPreferenceUtil.removeIdFromTriggeredTasks(getApplicationContext(), mTask.getId());
//Update alarms
AlarmManagerUtil.updateAlarms(getApplicationContext());
}
}
//If editing, Caller activity TaskDetailActivity will save the task.
BaseTransientBottomBar.BaseCallback<Snackbar> callback = new BaseTransientBottomBar.BaseCallback<Snackbar>() {
@Override
public void onDismissed(Snackbar transientBottomBar, int event) {
super.onDismissed(transientBottomBar, event);
Intent returnIntent = new Intent();
returnIntent.putExtra(HomeActivity.NEW_TASK_RETURN_REMINDER_TYPE, mTask.getReminderType());
returnIntent.putExtra(TaskActivity.TASK_TO_EDIT, mTask);
//Task was created, set result to OK
setResult(RESULT_OK, returnIntent);
finish();
}
};
SnackbarUtil.showSnackbar(mContainer, SnackbarUtil.SnackbarType.SUCCESS, R.string.activity_task_snackbar_save_successful, SnackbarUtil.SnackbarDuration.SHORT, callback);
} catch (CouldNotInsertDataException e) {
SnackbarUtil.showSnackbar(mContainer, SnackbarUtil.SnackbarType.ERROR, R.string.activity_task_snackbar_error_saving, SnackbarUtil.SnackbarDuration.SHORT, null);
}
}
use of android.support.design.widget.Snackbar in project Remindy by abicelis.
the class PlaceActivity method handleDeletePlace.
private void handleDeletePlace() {
mDao = new RemindyDAO(getApplicationContext());
final BaseTransientBottomBar.BaseCallback<Snackbar> callback = new BaseTransientBottomBar.BaseCallback<Snackbar>() {
@Override
public void onDismissed(Snackbar transientBottomBar, int event) {
super.onDismissed(transientBottomBar, event);
setResult(RESULT_OK);
finish();
}
};
//Check if Place is associated with at least one location-based reminder
List<Task> locationBasedTasks = new ArrayList<>();
try {
locationBasedTasks = mDao.getLocationBasedTasksAssociatedWithPlace(mPlace.getId(), -1);
} catch (CouldNotGetDataException e) {
SnackbarUtil.showSnackbar(mMapContainer, SnackbarUtil.SnackbarType.ERROR, R.string.activity_place_snackbar_error_deleting, SnackbarUtil.SnackbarDuration.LONG, null);
}
//if there are tasks that use this place, warn user
@StringRes int title = (locationBasedTasks.size() > 0 ? R.string.activity_place_dialog_delete_with_associated_tasks_title : R.string.activity_place_dialog_delete_title);
@StringRes int message = (locationBasedTasks.size() > 0 ? R.string.activity_place_dialog_delete_with_associated_tasks_message : R.string.activity_place_dialog_delete_message);
@StringRes int positive = (locationBasedTasks.size() > 0 ? R.string.activity_place_dialog_delete_with_associated_tasks_positive : R.string.activity_place_dialog_delete_positive);
@StringRes int negative = (locationBasedTasks.size() > 0 ? R.string.activity_place_dialog_delete_negative : R.string.activity_place_dialog_delete_negative);
AlertDialog dialog = new AlertDialog.Builder(this).setTitle(getResources().getString(title)).setMessage(getResources().getString(message)).setPositiveButton(getResources().getString(positive), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
mDao.deletePlace(mPlace.getId());
SnackbarUtil.showSnackbar(mMapContainer, SnackbarUtil.SnackbarType.SUCCESS, R.string.activity_place_snackbar_delete_succesful, SnackbarUtil.SnackbarDuration.SHORT, callback);
dialog.dismiss();
} catch (CouldNotDeleteDataException e) {
SnackbarUtil.showSnackbar(mMapContainer, SnackbarUtil.SnackbarType.ERROR, R.string.activity_place_snackbar_error_deleting, SnackbarUtil.SnackbarDuration.LONG, callback);
}
}
}).setNegativeButton(getResources().getString(negative), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).create();
dialog.show();
}
use of android.support.design.widget.Snackbar in project teaTime by ancfdy.
the class SnackbarUtils method IndefiniteSnackbar.
/**
* 自定义时常显示Snackbar,可选预设类型
* @param view
* @param message
* @param type
* @return
*/
public static Snackbar IndefiniteSnackbar(View view, String message, int duration, int type) {
Snackbar snackbar = Snackbar.make(view, message, Snackbar.LENGTH_INDEFINITE).setDuration(duration);
switchType(snackbar, type);
return snackbar;
}
use of android.support.design.widget.Snackbar in project teaTime by ancfdy.
the class SnackbarUtils method ShortSnackbar.
/**
* 短显示Snackbar,可选预设类型
* @param view
* @param message
* @param type
* @return
*/
public static Snackbar ShortSnackbar(View view, String message, int type) {
Snackbar snackbar = Snackbar.make(view, message, Snackbar.LENGTH_SHORT);
switchType(snackbar, type);
return snackbar;
}
Aggregations