Search in sources :

Example 1 with TableActivity

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;
}
Also used : AlertDialog(android.app.AlertDialog) Leg(org.hwyl.sexytopo.model.survey.Leg) Survey(org.hwyl.sexytopo.model.survey.Survey) LayoutInflater(android.view.LayoutInflater) TableActivity(org.hwyl.sexytopo.control.activity.TableActivity) WindowManager(android.view.WindowManager) Dialog(android.app.Dialog) R(org.hwyl.sexytopo.R) Station(org.hwyl.sexytopo.model.survey.Station) Editable(android.text.Editable) AlertDialog(android.app.AlertDialog) LRUD(org.hwyl.sexytopo.model.table.LRUD) TextView(android.widget.TextView) SurveyUpdater(org.hwyl.sexytopo.control.util.SurveyUpdater) SurveyManager(org.hwyl.sexytopo.control.SurveyManager) View(android.view.View) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) TextWatcher(android.text.TextWatcher) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 2 with TableActivity

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();
}
Also used : EditText(android.widget.EditText) AlertDialog(android.app.AlertDialog) Leg(org.hwyl.sexytopo.model.survey.Leg) Survey(org.hwyl.sexytopo.model.survey.Survey) LayoutInflater(android.view.LayoutInflater) TableActivity(org.hwyl.sexytopo.control.activity.TableActivity) WindowManager(android.view.WindowManager) Dialog(android.app.Dialog) R(org.hwyl.sexytopo.R) Station(org.hwyl.sexytopo.model.survey.Station) Editable(android.text.Editable) AlertDialog(android.app.AlertDialog) LRUD(org.hwyl.sexytopo.model.table.LRUD) TextView(android.widget.TextView) SurveyUpdater(org.hwyl.sexytopo.control.util.SurveyUpdater) SurveyManager(org.hwyl.sexytopo.control.SurveyManager) View(android.view.View) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) TextWatcher(android.text.TextWatcher) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable)

Aggregations

AlertDialog (android.app.AlertDialog)2 Dialog (android.app.Dialog)2 DialogInterface (android.content.DialogInterface)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 WindowManager (android.view.WindowManager)2 EditText (android.widget.EditText)2 TextView (android.widget.TextView)2 R (org.hwyl.sexytopo.R)2 SurveyManager (org.hwyl.sexytopo.control.SurveyManager)2 TableActivity (org.hwyl.sexytopo.control.activity.TableActivity)2 SurveyUpdater (org.hwyl.sexytopo.control.util.SurveyUpdater)2 Leg (org.hwyl.sexytopo.model.survey.Leg)2 Station (org.hwyl.sexytopo.model.survey.Station)2 Survey (org.hwyl.sexytopo.model.survey.Survey)2 LRUD (org.hwyl.sexytopo.model.table.LRUD)2