导航菜单

页面标题

页面副标题

xDrip+ v04633772025.07.16 - EditAlertActivity.java 源代码

正在查看: xDrip+ v04633772025.07.16 应用的 EditAlertActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.eveningoutpost.dexdrip;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.format.DateFormat;
import android.text.method.DigitsKeyListener;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.NumberPicker;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.eveningoutpost.dexdrip.EditAlertActivity;
import com.eveningoutpost.dexdrip.models.AlertType;
import com.eveningoutpost.dexdrip.models.BgReading;
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.models.UserError;
import com.eveningoutpost.dexdrip.ui.dialog.GenericConfirmDialog;
import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer;
import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder;
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
import com.eveningoutpost.dexdrip.utils.ActivityWithMenu;
import com.eveningoutpost.dexdrip.watch.thinjam.BlueJayEntry;
import com.eveningoutpost.dexdrip.wearintegration.WatchUpdaterService;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class EditAlertActivity extends ActivityWithMenu {
    private static final String TAG = AlertPlayer.class.getSimpleName();
    private boolean above;
    private EditText alertMp3File;
    private EditText alertText;
    private EditText alertThreshold;
    private String audioPath;
    private Button buttonPreSnooze;
    private Button buttonRemove;
    private Button buttonSave;
    private Button buttonTest;
    private Button buttonalertMp3;
    private CheckBox checkboxAllDay;
    private CheckBox checkboxDisabled;
    private CheckBox checkboxForceSpeaker;
    private CheckBox checkboxOverrideSilent;
    private CheckBox checkboxVibrate;
    private boolean doMgdl;
    private EditText editSnooze;
    private LinearLayout layoutSilentModeWarning;
    private LinearLayout layoutTimeBetween;
    private Context mContext;
    private EditText reraise;
    private LinearLayout timeInstructions;
    private TextView timeInstructionsEnd;
    private TextView timeInstructionsStart;
    private String uuid;
    private TextView viewAlertOverrideText;
    private TextView viewHeader;
    private TextView viewTimeEnd;
    private TextView viewTimeStart;
    private int startHour = 0;
    private int startMinute = 0;
    private int endHour = 23;
    private int endMinute = 59;
    private final int REQUEST_CODE_CHOOSE_FILE = 1;
    private final int MIN_ALERT = 40;
    private final int MAX_ALERT = BgReading.BG_READING_MAXIMUM_VALUE;

    String getExtra(Bundle bundle, String str, String str2) {
        String str3;
        if (bundle == null) {
            Bundle extras = getIntent().getExtras();
            str3 = extras == null ? null : extras.getString(str);
        } else {
            str3 = (String) bundle.getSerializable(str);
        }
        return str3 != null ? str3 : str2;
    }

    @Override
    protected void onResume() {
        xdrip.checkForcedEnglish(xdrip.getAppContext());
        super.onResume();
    }

    @Override
    protected void onCreate(Bundle bundle) {
        String str;
        int i;
        xdrip.checkForcedEnglish(xdrip.getAppContext());
        super.onCreate(bundle);
        this.mContext = this;
        setContentView(2131492908);
        this.viewHeader = (TextView) findViewById(2131297175);
        this.buttonSave = (Button) findViewById(2131296569);
        this.buttonRemove = (Button) findViewById(2131296568);
        this.buttonTest = (Button) findViewById(2131296570);
        this.buttonalertMp3 = (Button) findViewById(2131296260);
        this.buttonPreSnooze = (Button) findViewById(2131296567);
        this.alertText = (EditText) findViewById(2131296571);
        this.alertThreshold = (EditText) findViewById(2131296572);
        this.alertMp3File = (EditText) findViewById(2131296566);
        this.checkboxAllDay = (CheckBox) findViewById(2131296491);
        this.checkboxVibrate = (CheckBox) findViewById(2131296496);
        this.checkboxDisabled = (CheckBox) findViewById(2131297171);
        this.layoutTimeBetween = (LinearLayout) findViewById(2131297121);
        this.timeInstructions = (LinearLayout) findViewById(2131297123);
        this.timeInstructionsStart = (TextView) findViewById(2131297125);
        this.timeInstructionsEnd = (TextView) findViewById(2131297124);
        this.viewTimeStart = (TextView) findViewById(2131297183);
        this.viewTimeEnd = (TextView) findViewById(2131297182);
        this.editSnooze = (EditText) findViewById(2131296575);
        this.reraise = (EditText) findViewById(2131296914);
        this.layoutSilentModeWarning = (LinearLayout) findViewById(2131296701);
        this.viewAlertOverrideText = (TextView) findViewById(2131297177);
        this.checkboxOverrideSilent = (CheckBox) findViewById(2131296495);
        this.checkboxForceSpeaker = (CheckBox) findViewById(2131296492);
        getWindow().setSoftInputMode(3);
        addListenerOnButtons();
        if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
            this.viewHeader.setTextSize(2, 30.0f);
            this.buttonSave.setTextSize(2, 30.0f);
            this.buttonRemove.setTextSize(2, 30.0f);
            this.buttonTest.setTextSize(2, 30.0f);
            this.buttonalertMp3.setTextSize(2, 30.0f);
            this.buttonPreSnooze.setTextSize(2, 30.0f);
            this.alertText.setTextSize(2, 30.0f);
            this.alertThreshold.setTextSize(2, 30.0f);
            this.alertMp3File.setTextSize(2, 30.0f);
            this.checkboxAllDay.setTextSize(2, 30.0f);
            this.checkboxVibrate.setTextSize(2, 30.0f);
            this.checkboxDisabled.setTextSize(2, 30.0f);
            this.viewTimeStart.setTextSize(2, 30.0f);
            this.viewTimeEnd.setTextSize(2, 30.0f);
            this.editSnooze.setTextSize(2, 30.0f);
            this.reraise.setTextSize(2, 30.0f);
            this.viewAlertOverrideText.setTextSize(2, 30.0f);
            ((TextView) findViewById(2131297178)).setTextSize(2, 30.0f);
            ((TextView) findViewById(2131297179)).setTextSize(2, 30.0f);
            ((TextView) findViewById(2131297172)).setTextSize(2, 30.0f);
            ((TextView) findViewById(2131297176)).setTextSize(2, 30.0f);
            ((TextView) findViewById(2131297180)).setTextSize(2, 30.0f);
            ((TextView) findViewById(2131297181)).setTextSize(2, 30.0f);
            ((TextView) findViewById(2131297173)).setTextSize(2, 30.0f);
        }
        int i2 = 1;
        boolean z = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("units", "mgdl").compareTo("mgdl") == 0;
        this.doMgdl = z;
        if (!z) {
            this.alertThreshold.setInputType(2);
            this.alertThreshold.setInputType(8192);
            this.alertThreshold.setKeyListener(DigitsKeyListener.getInstance(false, true));
        }
        String extra = getExtra(bundle, "uuid", null);
        this.uuid = extra;
        if (extra == null) {
            this.above = Boolean.parseBoolean(getExtra(bundle, "above", null));
            this.checkboxAllDay.setChecked(true);
            this.checkboxVibrate.setChecked(true);
            this.checkboxDisabled.setChecked(false);
            this.checkboxOverrideSilent.setChecked(true);
            this.checkboxForceSpeaker.setChecked(true);
            this.audioPath = "";
            this.alertMp3File.setText(shortPath(""));
            this.alertMp3File.setKeyListener(null);
            i = SnoozeActivity.getDefaultSnooze(this.above);
            this.buttonRemove.setVisibility(8);
            this.buttonPreSnooze.setVisibility(8);
            StringBuilder sb = new StringBuilder();
            sb.append(getString(2131755079));
            sb.append(" ");
            sb.append(this.above ? getString(2131755656) : getString(2131755777));
            sb.append(" ");
            sb.append(getString(2131755099));
            str = sb.toString();
            this.startHour = 0;
            this.startMinute = 0;
            this.endHour = 23;
            this.endMinute = 59;
        } else {
            AlertType alertType = AlertType.get_alert(extra);
            if (alertType == null) {
                UserError.Log.wtf(TAG, "Error editing alert, when that alert does not exist...");
                setResult(0, new Intent());
                finish();
                return;
            }
            this.above = alertType.above;
            this.alertText.setText(alertType.name);
            this.alertThreshold.setText(unitsConvert2Disp(this.doMgdl, alertType.threshold));
            this.checkboxAllDay.setChecked(alertType.all_day);
            this.checkboxVibrate.setChecked(alertType.vibrate);
            this.checkboxDisabled.setChecked(true ^ alertType.active);
            this.checkboxOverrideSilent.setChecked(alertType.override_silent_mode);
            this.checkboxForceSpeaker.setChecked(alertType.force_speaker);
            int i3 = alertType.default_snooze;
            if (i3 == 0) {
                SnoozeActivity.getDefaultSnooze(this.above);
            }
            String extra2 = getExtra(bundle, "audioPath", alertType.mp3_file);
            this.audioPath = extra2;
            this.alertMp3File.setText(shortPath(extra2));
            StringBuilder sb2 = new StringBuilder();
            sb2.append(getString(2131755491));
            sb2.append(" ");
            sb2.append(this.above ? getString(2131755656) : getString(2131755777));
            sb2.append(" ");
            sb2.append(getString(2131755099));
            String sb3 = sb2.toString();
            this.startHour = AlertType.time2Hours(alertType.start_time_minutes);
            this.startMinute = AlertType.time2Minutes(alertType.start_time_minutes);
            this.endHour = AlertType.time2Hours(alertType.end_time_minutes);
            this.endMinute = AlertType.time2Minutes(alertType.end_time_minutes);
            int i4 = alertType.minutes_between;
            if (this.uuid.equals(AlertType.LOW_ALERT_55)) {
                this.alertText.setKeyListener(null);
                this.alertThreshold.setKeyListener(null);
                this.buttonalertMp3.setEnabled(false);
                this.checkboxAllDay.setEnabled(false);
                this.checkboxVibrate.setEnabled(false);
                this.checkboxOverrideSilent.setEnabled(false);
                this.checkboxForceSpeaker.setEnabled(false);
                this.reraise.setEnabled(false);
            }
            str = sb3;
            i = i3;
            i2 = i4;
        }
        this.reraise.setText(String.valueOf(i2));
        this.alertMp3File.setKeyListener(null);
        this.viewHeader.setText(str);
        setDefaultSnoozeSpinner(i);
        setPreSnoozeSpinner();
        enableAllDayControls();
        setDisabledView();
        showHideSilentModeWarning();
    }

    @Override
    public void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        bundle.putString("uuid", this.uuid);
        bundle.putString("above", String.valueOf(this.above));
        bundle.putString("audioPath", this.audioPath);
    }

    @Override
    public String getMenuName() {
        return getString(2131756659);
    }

    public static DecimalFormat getNumberFormatter(boolean z) {
        DecimalFormat decimalFormat = new DecimalFormat("#");
        if (z) {
            decimalFormat.setMaximumFractionDigits(0);
            decimalFormat.setMinimumFractionDigits(0);
        } else {
            decimalFormat.setMaximumFractionDigits(1);
            decimalFormat.setMinimumFractionDigits(1);
        }
        return decimalFormat;
    }

    public static String unitsConvert2Disp(boolean z, double d) {
        DecimalFormat numberFormatter = getNumberFormatter(z);
        if (z) {
            return numberFormatter.format(d);
        }
        return numberFormatter.format(d / 18.0182d);
    }

    double unitsConvertFromDisp(double d) {
        return this.doMgdl ? d : d * 18.0182d;
    }

    void enableAllDayControls() {
        if (this.checkboxAllDay.isChecked()) {
            this.layoutTimeBetween.setVisibility(8);
            this.timeInstructions.setVisibility(8);
        } else {
            setTimeRanges();
        }
    }

    void setDisabledView() {
        boolean isChecked = this.checkboxDisabled.isChecked();
        ArrayList arrayList = new ArrayList();
        arrayList.add((TextView) findViewById(2131297178));
        arrayList.add((TextView) findViewById(2131297179));
        arrayList.add((TextView) findViewById(2131297172));
        arrayList.add((TextView) findViewById(2131297176));
        arrayList.add((TextView) findViewById(2131297181));
        arrayList.add((TextView) findViewById(2131297173));
        arrayList.add((TextView) findViewById(2131297180));
        arrayList.add((TextView) findViewById(2131297177));
        arrayList.add((TextView) findViewById(2131297184));
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            TextView textView = (TextView) it.next();
            if (isChecked) {
                textView.setPaintFlags(textView.getPaintFlags() | 16);
            } else {
                textView.setPaintFlags(textView.getPaintFlags() & (-17));
            }
        }
    }

    void showHideSilentModeWarning() {
        this.layoutSilentModeWarning.setVisibility(this.checkboxOverrideSilent.isChecked() ? 8 : 0);
    }

    public boolean verifyThreshold(double d, boolean z, int i, int i2) {
        String str;
        String str2;
        List<AlertType> all = AlertType.getAll(false);
        List<AlertType> all2 = AlertType.getAll(true);
        if (d < 40.0d || d > 400.0d) {
            Toast.makeText(getApplicationContext(), "threshold has to be between " + unitsConvert2Disp(this.doMgdl, 40.0d) + " and " + unitsConvert2Disp(this.doMgdl, 400.0d), 1).show();
            return false;
        }
        for (AlertType alertType : all) {
            if (alertType.threshold == d && overlapping(alertType, z, i, i2) && alertType.active && ((str2 = this.uuid) == null || !str2.equals(alertType.uuid))) {
                Toast.makeText(getApplicationContext(), "Each alert should have it's own threshold. Please choose another threshold.", 1).show();
                return false;
            }
        }
        for (AlertType alertType2 : all2) {
            if (alertType2.threshold == d && overlapping(alertType2, z, i, i2) && alertType2.active && ((str = this.uuid) == null || !str.equals(alertType2.uuid))) {
                Toast.makeText(getApplicationContext(), "Each alert should have it's own threshold. Please choose another threshold.", 1).show();
                return false;
            }
        }
        if (this.above) {
            for (AlertType alertType3 : all) {
                if (d < alertType3.threshold && overlapping(alertType3, z, i, i2) && alertType3.active) {
                    Toast.makeText(getApplicationContext(), "High alert threshold has to be higher than all low alerts. Please choose another threshold.", 1).show();
                    return false;
                }
            }
        } else {
            for (AlertType alertType4 : all2) {
                if (d > alertType4.threshold && overlapping(alertType4, z, i, i2) && alertType4.active) {
                    Toast.makeText(getApplicationContext(), "Low alert threshold has to be lower than all high alerts. Please choose another threshold.", 1).show();
                    return false;
                }
            }
        }
        return true;
    }

    private boolean overlapping(AlertType alertType, boolean z, int i, int i2) {
        if (alertType.all_day || z) {
            return true;
        }
        int i3 = alertType.start_time_minutes;
        int i4 = alertType.end_time_minutes;
        if (i3 <= i && i4 > i) {
            return true;
        }
        if (i3 <= i && i2 < i && i2 > i3) {
            return true;
        }
        if (i <= i3 && i2 > i3) {
            return true;
        }
        if (i > i3 || i4 >= i3 || i4 <= i) {
            return i4 < i3 && i2 < i;
        }
        return true;
    }

    private double parseDouble(String str) {
        try {
            return getNumberFormatter(this.doMgdl).parse(str).doubleValue();
        } catch (NumberFormatException e) {
            UserError.Log.e(TAG, "Invalid number", e);
            Toast.makeText(getApplicationContext(), "Invalid number: " + str, 1).show();
            return Double.NaN;
        } catch (ParseException e2) {
            UserError.Log.e(TAG, "Invalid number", e2);
            Toast.makeText(getApplicationContext(), "Invalid number: " + str, 1).show();
            return Double.NaN;
        }
    }

    public int safeGetDefaultSnooze() {
        try {
            return parseInt(this.editSnooze.getText().toString()).intValue();
        } catch (NullPointerException e) {
            UserError.Log.wtf(TAG, "Got null pointer exception unboxing parseInt: ", e);
            return SnoozeActivity.getDefaultSnooze(this.above);
        }
    }

    public Integer parseInt(String str) {
        try {
            return Integer.valueOf(Integer.parseInt(str));
        } catch (NumberFormatException e) {
            UserError.Log.e(TAG, "Invalid number", e);
            Toast.makeText(getApplicationContext(), "Invalid number: " + str, 1).show();
            return null;
        }
    }

    public void addListenerOnButtons() {
        this.buttonSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                double d = JoH.tolerantParseDouble(EditAlertActivity.this.alertThreshold.getText().toString());
                if (Double.isNaN(d)) {
                    return;
                }
                double unitsConvertFromDisp = EditAlertActivity.this.unitsConvertFromDisp(d);
                EditAlertActivity editAlertActivity = EditAlertActivity.this;
                Integer parseInt = editAlertActivity.parseInt(editAlertActivity.reraise.getText().toString());
                if (parseInt == null) {
                    return;
                }
                int intValue = parseInt.intValue();
                int safeGetDefaultSnooze = EditAlertActivity.this.safeGetDefaultSnooze();
                if (intValue < 1) {
                    Toast.makeText(EditAlertActivity.this.getApplicationContext(), "Reraise Value must be 1 minute or greater", 1).show();
                    return;
                }
                if (intValue < safeGetDefaultSnooze) {
                    int time = AlertType.toTime(EditAlertActivity.this.startHour, EditAlertActivity.this.startMinute);
                    int time2 = AlertType.toTime(EditAlertActivity.this.endHour, EditAlertActivity.this.endMinute);
                    boolean isChecked = EditAlertActivity.this.checkboxAllDay.isChecked();
                    if (time == AlertType.toTime(23, 59)) {
                        time++;
                    }
                    int i = time;
                    if (time2 == AlertType.toTime(23, 59)) {
                        time2++;
                    }
                    int i2 = time2;
                    boolean z = (i == AlertType.toTime(0, 0) && i2 == AlertType.toTime(24, 0)) ? true : isChecked;
                    if (i != i2 || z) {
                        boolean isChecked2 = EditAlertActivity.this.checkboxDisabled.isChecked();
                        if (isChecked2 || EditAlertActivity.this.verifyThreshold(unitsConvertFromDisp, z, i, i2)) {
                            boolean isChecked3 = EditAlertActivity.this.checkboxVibrate.isChecked();
                            boolean isChecked4 = EditAlertActivity.this.checkboxOverrideSilent.isChecked();
                            boolean isChecked5 = EditAlertActivity.this.checkboxForceSpeaker.isChecked();
                            String str = EditAlertActivity.this.audioPath;
                            if (EditAlertActivity.this.uuid != null) {
                                AlertType.update_alert(EditAlertActivity.this.uuid, EditAlertActivity.this.alertText.getText().toString(), EditAlertActivity.this.above, unitsConvertFromDisp, z, intValue, str, i, i2, isChecked4, isChecked5, safeGetDefaultSnooze, isChecked3, !isChecked2);
                            } else {
                                AlertType.add_alert(null, EditAlertActivity.this.alertText.getText().toString(), EditAlertActivity.this.above, unitsConvertFromDisp, z, intValue, str, i, i2, isChecked4, isChecked5, safeGetDefaultSnooze, isChecked3, !isChecked2);
                            }
                            Home.startWatchUpdaterService(EditAlertActivity.this.mContext, WatchUpdaterService.ACTION_SYNC_ALERTTYPE, EditAlertActivity.TAG);
                            EditAlertActivity.this.setResult(-1, new Intent());
                            BlueJayEntry.startWithRefreshIfEnabled();
                            EditAlertActivity.this.finish();
                            return;
                        }
                        return;
                    }
                    Toast.makeText(EditAlertActivity.this.getApplicationContext(), "start time and end time of alert can not be equal", 1).show();
                    return;
                }
                Toast.makeText(EditAlertActivity.this.getApplicationContext(), "Reraise Value must be less than snooze length", 1).show();
            }
        });
        this.buttonRemove.setOnClickListener(new AnonymousClass2());
        this.buttonTest.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EditAlertActivity.this.testAlert();
            }
        });
        this.buttonalertMp3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog.Builder builder = new AlertDialog.Builder(EditAlertActivity.this.mContext);
                builder.setTitle("What type of Alert?").setItems(2130903066, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        if (i == 0) {
                            Intent intent = new Intent("android.intent.action.RINGTONE_PICKER");
                            intent.putExtra("android.intent.extra.ringtone.TITLE", EditAlertActivity.this.getString(2131756263));
                            intent.putExtra("android.intent.extra.ringtone.SHOW_SILENT", true);
                            intent.putExtra("android.intent.extra.ringtone.SHOW_DEFAULT", true);
                            intent.putExtra("android.intent.extra.ringtone.TYPE", 7);
                            EditAlertActivity.this.startActivityForResult(intent, 999);
                            return;
                        }
                        if (i == 1) {
                            if (EditAlertActivity.this.checkPermissions()) {
                                EditAlertActivity.this.chooseFile();
                            }
                        } else {
                            EditAlertActivity.this.audioPath = "";
                            EditAlertActivity.this.alertMp3File.setText(EditAlertActivity.shortPath(EditAlertActivity.this.audioPath));
                        }
                    }
                });
                builder.create().show();
            }
        });
        this.checkboxAllDay.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
                EditAlertActivity.this.enableAllDayControls();
            }
        });
        this.checkboxDisabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
                EditAlertActivity.this.setDisabledView();
            }
        });
        this.checkboxOverrideSilent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
                EditAlertActivity.this.showHideSilentModeWarning();
            }
        });
        View.OnClickListener onClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                TimePickerDialog timePickerDialog = new TimePickerDialog(EditAlertActivity.this.mContext, 2, new TimePickerDialog.OnTimeSetListener() {
                    @Override
                    public void onTimeSet(TimePicker timePicker, int i, int i2) {
                        EditAlertActivity.this.startHour = i;
                        EditAlertActivity.this.startMinute = i2;
                        EditAlertActivity.this.setTimeRanges();
                    }
                }, EditAlertActivity.this.startHour, EditAlertActivity.this.startMinute, DateFormat.is24HourFormat(EditAlertActivity.this.mContext));
                timePickerDialog.setTitle(EditAlertActivity.this.getString(2131756260));
                timePickerDialog.show();
            }
        };
        View.OnClickListener onClickListener2 = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                TimePickerDialog timePickerDialog = new TimePickerDialog(EditAlertActivity.this.mContext, 2, new TimePickerDialog.OnTimeSetListener() {
                    @Override
                    public void onTimeSet(TimePicker timePicker, int i, int i2) {
                        EditAlertActivity.this.endHour = i;
                        EditAlertActivity.this.endMinute = i2;
                        EditAlertActivity.this.setTimeRanges();
                    }
                }, EditAlertActivity.this.endHour, EditAlertActivity.this.endMinute, DateFormat.is24HourFormat(EditAlertActivity.this.mContext));
                timePickerDialog.setTitle(EditAlertActivity.this.getString(2131756260));
                timePickerDialog.show();
            }
        };
        this.viewTimeStart.setOnClickListener(onClickListener);
        this.timeInstructionsStart.setOnClickListener(onClickListener);
        this.viewTimeEnd.setOnClickListener(onClickListener2);
        this.timeInstructionsEnd.setOnClickListener(onClickListener2);
    }

    class AnonymousClass2 implements View.OnClickListener {
        AnonymousClass2() {
        }

        @Override
        public void onClick(View view) {
            GenericConfirmDialog.show(EditAlertActivity.this, xdrip.gs(2131755152), xdrip.gs(2131757083), new Runnable() {
                @Override
                public final void run() {
                    EditAlertActivity.AnonymousClass2.this.lambda$onClick$0();
                }
            });
        }

        public void lambda$onClick$0() {
            if (EditAlertActivity.this.uuid == null) {
                UserError.Log.wtf(EditAlertActivity.TAG, "Error remove pressed, while we were adding an alert");
            } else {
                AlertType.remove_alert(EditAlertActivity.this.uuid);
                Home.startWatchUpdaterService(EditAlertActivity.this.mContext, WatchUpdaterService.ACTION_SYNC_ALERTTYPE, EditAlertActivity.TAG);
            }
            EditAlertActivity.this.setResult(-1, new Intent());
            EditAlertActivity.this.finish();
        }
    }

    public void chooseFile() {
        Intent intent = new Intent();
        intent.setType("audio/*");
        intent.setAction("android.intent.action.OPEN_DOCUMENT");
        startActivityForResult(Intent.createChooser(intent, getString(2131756256)), 1);
    }

    @Override
    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        super.onRequestPermissionsResult(i, strArr, iArr);
        if (i == 138) {
            if (iArr.length > 0 && iArr[0] == 0) {
                chooseFile();
            } else {
                JoH.static_toast_long(this, getString(2131755286));
            }
        }
    }

    @Override
    public void onActivityResult(int i, int i2, Intent intent) {
        if (i2 == -1) {
            Uri uri = (Uri) intent.getParcelableExtra("android.intent.extra.ringtone.PICKED_URI");
            if (uri != null) {
                this.audioPath = uri.toString();
                UserError.Log.d(TAG, "Selected ringtone audio path: " + this.audioPath);
                this.alertMp3File.setText(shortPath(this.audioPath));
                return;
            }
            if (i == 1) {
                try {
                    Uri data = intent.getData();
                    getContentResolver().takePersistableUriPermission(data, 1);
                    String displayNameFromURI = getDisplayNameFromURI(data);
                    if (displayNameFromURI == null) {
                        displayNameFromURI = data.getPath();
                    }
                    UserError.Log.d(TAG, "Selected audio path: " + displayNameFromURI + " " + data);
                    this.audioPath = data.toString();
                    this.alertMp3File.setText(shortPath(displayNameFromURI));
                } catch (Exception e) {
                    JoH.static_toast_long(getString(2131756149) + " " + e.getMessage());
                }
            }
        }
    }

    private static String getDisplayNameFromURI(Uri uri) {
        String fieldFromURI = JoH.getFieldFromURI("title", uri);
        return (fieldFromURI == null || uri.toString().endsWith(fieldFromURI)) ? JoH.getFieldFromURI("_display_name", uri) : fieldFromURI;
    }

    public static String timeFormatString(Context context, int i, int i2) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
        StringBuilder sb = new StringBuilder();
        sb.append(i);
        sb.append(":");
        sb.append(i2 < 10 ? "0" : "");
        sb.append(i2);
        String sb2 = sb.toString();
        if (!DateFormat.is24HourFormat(context)) {
            try {
                return new SimpleDateFormat("hh:mm aa").format(simpleDateFormat.parse(sb2));
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return sb2;
    }

    public void setTimeRanges() {
        this.timeInstructions.setVisibility(0);
        this.layoutTimeBetween.setVisibility(0);
        this.viewTimeStart.setText(timeFormatString(this.mContext, this.startHour, this.startMinute));
        this.viewTimeEnd.setText(timeFormatString(this.mContext, this.endHour, this.endMinute));
    }

    public static boolean isPathRingtone(Context context, String str) {
        return (str == null || str.isEmpty() || RingtoneManager.getRingtone(context, Uri.parse(str)) == null) ? false : true;
    }

    static String shortPath(String str) {
        String displayNameFromURI;
        if (str == null) {
            return "";
        }
        if (str.length() == 0) {
            return "xDrip Default";
        }
        if (str.startsWith("content:") && (displayNameFromURI = getDisplayNameFromURI(Uri.parse(str))) != null) {
            return displayNameFromURI;
        }
        if (isPathRingtone(xdrip.getAppContext(), str)) {
            String title = RingtoneManager.getRingtone(xdrip.getAppContext(), Uri.parse(str)).getTitle(xdrip.getAppContext());
            UserError.Log.d(TAG, "Ringtone title: " + title);
            return title;
        }
        String[] split = str.split("/");
        return split.length > 1 ? split[split.length - 1] : str;
    }

    public void setDefaultSnoozeSpinner(int i) {
        this.editSnooze.setText(String.valueOf(i));
        this.editSnooze.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (motionEvent.getAction() != 0) {
                    return false;
                }
                final Dialog dialog = new Dialog(EditAlertActivity.this.mContext);
                dialog.setTitle("Default Snooze");
                dialog.setContentView(2131493081);
                Button button = (Button) dialog.findViewById(2131296418);
                Button button2 = (Button) dialog.findViewById(2131296429);
                final NumberPicker numberPicker = (NumberPicker) dialog.findViewById(2131296823);
                SnoozeActivity.SetSnoozePickerValues(numberPicker, EditAlertActivity.this.above, EditAlertActivity.this.safeGetDefaultSnooze());
                button.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view2) {
                        EditAlertActivity.this.editSnooze.setText(String.valueOf(SnoozeActivity.getTimeFromSnoozeValue(numberPicker.getValue())));
                        dialog.dismiss();
                    }
                });
                button2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view2) {
                        dialog.dismiss();
                    }
                });
                dialog.show();
                return false;
            }
        });
    }

    public void setPreSnoozeSpinner() {
        this.buttonPreSnooze.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final Dialog dialog = new Dialog(EditAlertActivity.this.mContext);
                dialog.setTitle("Snooze this alert...");
                dialog.setContentView(2131493081);
                Button button = (Button) dialog.findViewById(2131296418);
                Button button2 = (Button) dialog.findViewById(2131296429);
                button.setText("pre-Snooze");
                final NumberPicker numberPicker = (NumberPicker) dialog.findViewById(2131296823);
                SnoozeActivity.SetSnoozePickerValues(numberPicker, EditAlertActivity.this.above, EditAlertActivity.this.safeGetDefaultSnooze());
                button.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view2) {
                        AlertPlayer.getPlayer().PreSnooze(EditAlertActivity.this.getApplicationContext(), EditAlertActivity.this.uuid, SnoozeActivity.getTimeFromSnoozeValue(numberPicker.getValue()));
                        dialog.dismiss();
                    }
                });
                button2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view2) {
                        dialog.dismiss();
                    }
                });
                dialog.show();
            }
        });
    }

    public boolean checkPermissions() {
        if (ContextCompat.checkSelfPermission(getApplicationContext(), "android.permission.WRITE_EXTERNAL_STORAGE") == 0) {
            return true;
        }
        JoH.show_ok_dialog(this, xdrip.gs(2131756012), xdrip.gs(2131755880), new Runnable() {
            @Override
            public void run() {
                ActivityCompat.requestPermissions(this, new String[]{"android.permission.WRITE_EXTERNAL_STORAGE"}, 138);
            }
        });
        return false;
    }

    public void testAlert() {
        double parseDouble = parseDouble(this.alertThreshold.getText().toString());
        if (Double.isNaN(parseDouble)) {
            JoH.static_toast_long("Threshold number is not valid");
            return;
        }
        double unitsConvertFromDisp = unitsConvertFromDisp(parseDouble);
        int time = AlertType.toTime(this.startHour, this.startMinute);
        int time2 = AlertType.toTime(this.endHour, this.endMinute);
        boolean isChecked = this.checkboxAllDay.isChecked();
        if (time == AlertType.toTime(23, 59)) {
            time++;
        }
        int i = time;
        if (time2 == AlertType.toTime(23, 59)) {
            time2++;
        }
        int i2 = time2;
        boolean z = (i == AlertType.toTime(0, 0) && i2 == AlertType.toTime(24, 0)) ? true : isChecked;
        if (i == i2 && !z) {
            Toast.makeText(getApplicationContext(), "start time and end time of alert can not be equal", 1).show();
            return;
        }
        if (verifyThreshold(unitsConvertFromDisp, z, i, i2)) {
            boolean isChecked2 = this.checkboxVibrate.isChecked();
            boolean isChecked3 = this.checkboxOverrideSilent.isChecked();
            boolean isChecked4 = this.checkboxForceSpeaker.isChecked();
            String str = this.audioPath;
            try {
                int safeGetDefaultSnooze = safeGetDefaultSnooze();
                if (Pref.getBooleanDefaultFalse("start_snoozed")) {
                    JoH.static_toast_long("Start Snoozed setting means alert would normally start silent");
                } else if (Pref.getStringDefaultBlank("bg_alert_profile").equals("ascending") && Pref.getBoolean("delay_ascending_3min", true)) {
                    JoH.static_toast_long("Ascending Volume Profile + delayed ascending means it will start silent");
                } else if (Pref.getStringDefaultBlank("bg_alert_profile").equals("Silent")) {
                    JoH.static_toast_long("Volume Profile is set to silent!");
                }
                AlertType.testAlert(this.alertText.getText().toString(), this.above, unitsConvertFromDisp, z, 1, str, i, i2, isChecked3, isChecked4, safeGetDefaultSnooze, isChecked2, this.mContext);
            } catch (NullPointerException unused) {
                JoH.static_toast_long("Snooze value is not a number - cannot test");
            }
        }
    }
}