use of org.hwyl.sexytopo.control.activity.TableActivity in project sexytopo by richsmith.
the class ManualEntry method createDialog.
private static AlertDialog createDialog(int layoutId, final TableActivity tableActivity, final EditCallback editCallback) {
AlertDialog.Builder builder = new AlertDialog.Builder(tableActivity);
LayoutInflater inflater = tableActivity.getLayoutInflater();
final View dialogView = inflater.inflate(layoutId, null);
if (tableActivity.getBooleanPreference("pref_key_deg_mins_secs")) {
dialogView.findViewById(R.id.azimuth_standard).setVisibility(View.GONE);
dialogView.findViewById(R.id.azimuth_deg_mins_secs).setVisibility(View.VISIBLE);
}
builder.setView(dialogView).setTitle(R.string.manual_add_station_title).setPositiveButton("Save", (dialog, buttonId) -> {
/* Do nothing */
}).setNegativeButton("Cancel", (dialog, buttonId) -> {
/* Do nothing */
});
final AlertDialog dialog = builder.create();
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
dialog.show();
dialog.setButton(DialogInterface.BUTTON_POSITIVE, "Save", (dialogInterface, buttonId) -> {
Float distance = getFieldValue(dialog, R.id.editDistance);
Float inclination = getFieldValue(dialog, R.id.editInclination);
Float azimuth;
if (tableActivity.getBooleanPreference("pref_key_deg_mins_secs")) {
Float degrees = getFieldValue(dialog, R.id.editAzimuthDegrees);
Float minutes = getFieldValue(dialog, R.id.editAzimuthMinutes);
Float seconds = getFieldValue(dialog, R.id.editAzimuthSeconds);
if (degrees == null || minutes == null || seconds == null) {
azimuth = null;
} else {
azimuth = degrees + (minutes * (1.0f / 60.0f)) + (seconds * (1.0f / 60.0f) * (1.0f / 60.0f));
}
} else {
azimuth = getFieldValue(dialog, R.id.editAzimuth);
}
if (distance == null || !Leg.isDistanceLegal(distance)) {
TextView editDistance = dialogView.findViewById(R.id.editDistance);
editDistance.setError("Bad distance");
tableActivity.showSimpleToast("Bad distance");
} else if (azimuth == null || !Leg.isAzimuthLegal(azimuth)) {
TextView editAzimuth = dialogView.findViewById(R.id.editAzimuth);
tableActivity.showSimpleToast("Bad azimuth");
editAzimuth.setError("Bad azimuth");
} else if (inclination == null || !Leg.isInclinationLegal(inclination)) {
TextView editInclination = dialogView.findViewById(R.id.editInclination);
editInclination.setError("Bad inclination");
tableActivity.showSimpleToast("Bad inclination " + inclination);
} else {
dialogInterface.dismiss();
Leg leg = new Leg(distance, azimuth, inclination);
editCallback.submit(leg, dialog);
}
});
return dialog;
}
use of org.hwyl.sexytopo.control.activity.TableActivity in project sexytopo by richsmith.
the class ManualEntry method renameStation.
public static void renameStation(final TableActivity activity, final Survey survey, final Station toRename) {
final EditText renameField = new EditText(activity);
renameField.setText(toRename.getName());
renameField.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
// nothing
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// nothing
}
public void afterTextChanged(Editable s) {
String currentName = toRename.getName();
String currentText = renameField.getText().toString();
// only check for non-null or max length
if (currentText.isEmpty()) {
renameField.setError("Cannot be blank");
} else if (currentText.equals("-")) {
renameField.setError("Station cannot be named \"-\"");
} else if (!currentText.equals(currentName) && (survey.getStationByName(currentText) != null)) {
renameField.setError("Station name must be unique");
} else {
renameField.setError(null);
}
}
});
AlertDialog dialog = new AlertDialog.Builder(activity).setTitle("Edit name").setView(renameField).setPositiveButton("Rename", (ignore, buttonId) -> {
String newName = renameField.getText().toString();
try {
SurveyUpdater.renameStation(survey, toRename, newName);
activity.syncTableWithSurvey();
} catch (Exception e) {
activity.showSimpleToast("Rename failed");
}
}).setNegativeButton("Cancel", (ignore, buttonId) -> {
/* Do nothing */
}).create();
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
dialog.show();
}
Aggregations