导航菜单

页面标题

页面副标题

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

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

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


package com.eveningoutpost.dexdrip;

import android.app.Dialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.Button;
import android.widget.NumberPicker;
import android.widget.TextView;
import androidx.appcompat.R$styleable;
import com.eveningoutpost.dexdrip.models.ActiveBgAlert;
import com.eveningoutpost.dexdrip.models.AlertType;
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.models.UserError;
import com.eveningoutpost.dexdrip.services.MissedReadingService;
import com.eveningoutpost.dexdrip.utilitymodels.AlertPlayer;
import com.eveningoutpost.dexdrip.utilitymodels.BgGraphBuilder;
import com.eveningoutpost.dexdrip.utilitymodels.Notifications;
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
import com.eveningoutpost.dexdrip.utils.ActivityWithMenu;
import java.text.MessageFormat;
import java.util.Date;

public class SnoozeActivity extends ActivityWithMenu {
    private static String status;
    TextView alertStatus;
    Button buttonSnooze;
    Button clearDisabled;
    Button clearHighDisabled;
    Button clearLowDisabled;
    Button disableAlerts;
    Button disableHighAlerts;
    Button disableLowAlerts;
    boolean doMgdl;
    SharedPreferences prefs;
    Button sendRemoteSnooze;
    NumberPicker snoozeValue;
    static final int[] snoozeValues = {10, 15, 20, 30, 40, 50, 60, 75, 90, R$styleable.AppCompatTheme_windowFixedWidthMajor, 150, 180, 240, 300, 360, 420, 480, 540, 600, 720};
    private static final String TAG = AlertPlayer.class.getSimpleName();

    public static int getDefaultSnooze(boolean z) {
        if (z) {
            return R$styleable.AppCompatTheme_windowFixedWidthMajor;
        }
        return 35;
    }

    public enum SnoozeType {
        ALL_ALERTS("alerts_disabled_until"),
        LOW_ALERTS("low_alerts_disabled_until"),
        HIGH_ALERTS("high_alerts_disabled_until");

        private final String prefKey;

        SnoozeType(String str) {
            this.prefKey = str;
        }

        public String getPrefKey() {
            return this.prefKey;
        }
    }

    public static void snoozeForType(long j, SnoozeType snoozeType, SharedPreferences sharedPreferences) {
        boolean z;
        if (j == -1) {
            j = 5256000;
        }
        sharedPreferences.edit().putLong(snoozeType.getPrefKey(), new Date().getTime() + (j * 1000 * 60)).apply();
        if (ActiveBgAlert.getOnly() != null) {
            AlertType alertTypegetOnly = ActiveBgAlert.alertTypegetOnly();
            if (snoozeType == SnoozeType.ALL_ALERTS || (((z = alertTypegetOnly.above) && snoozeType == SnoozeType.HIGH_ALERTS) || (!z && snoozeType == SnoozeType.LOW_ALERTS))) {
                ActiveBgAlert.ClearData();
            }
        }
        if (snoozeType == SnoozeType.ALL_ALERTS) {
            sharedPreferences.edit().putLong(SnoozeType.HIGH_ALERTS.getPrefKey(), 0L).apply();
            sharedPreferences.edit().putLong(SnoozeType.LOW_ALERTS.getPrefKey(), 0L).apply();
        }
        recheckAlerts();
    }

    static int getSnoozeLocation(int i) {
        int i2 = 0;
        while (true) {
            int[] iArr = snoozeValues;
            if (i2 < iArr.length) {
                int i3 = iArr[i2];
                if (i == i3) {
                    return i2;
                }
                if (i < i3) {
                    if (i2 == 0) {
                        return 0;
                    }
                    return i2 - 1;
                }
                i2++;
            } else {
                return iArr.length - 1;
            }
        }
    }

    static String getNameFromTime(int i) {
        if (i < 120) {
            return i + " minutes";
        }
        return (i / 60.0d) + " hours";
    }

    static int getTimeFromSnoozeValue(int i) {
        return snoozeValues[i];
    }

    static void SetSnoozePickerValues(NumberPicker numberPicker, boolean z, int i) {
        int length = snoozeValues.length;
        String[] strArr = new String[length];
        for (int i2 = 0; i2 < length; i2++) {
            strArr[i2] = getNameFromTime(snoozeValues[i2]);
        }
        numberPicker.setMaxValue(length - 1);
        numberPicker.setMinValue(0);
        numberPicker.setDisplayedValues(strArr);
        numberPicker.setWrapSelectorWheel(false);
        if (i != 0) {
            numberPicker.setValue(getSnoozeLocation(i));
        } else {
            numberPicker.setValue(getSnoozeLocation(getDefaultSnooze(z)));
        }
    }

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if (Home.get_holo()) {
            setTheme(2131820788);
        }
        JoH.fixActionBar(this);
        setContentView(2131492941);
        this.alertStatus = (TextView) findViewById(2131296360);
        this.snoozeValue = (NumberPicker) findViewById(2131297002);
        SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        this.prefs = defaultSharedPreferences;
        this.doMgdl = defaultSharedPreferences.getString("units", "mgdl").compareTo("mgdl") == 0;
        addListenerOnButton();
        if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
            this.alertStatus.setTextSize(2, 30.0f);
            this.buttonSnooze.setTextSize(2, 30.0f);
        }
        displayStatus();
    }

    @Override
    public void onWindowFocusChanged(boolean z) {
        super.onWindowFocusChanged(z);
        if (z) {
            displayStatus();
        }
    }

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

    public void addListenerOnButton() {
        this.buttonSnooze = (Button) findViewById(2131296468);
        this.disableLowAlerts = (Button) findViewById(2131296465);
        this.clearLowDisabled = (Button) findViewById(2131296580);
        this.disableHighAlerts = (Button) findViewById(2131296464);
        this.clearHighDisabled = (Button) findViewById(2131296579);
        this.disableAlerts = (Button) findViewById(2131296463);
        this.clearDisabled = (Button) findViewById(2131296578);
        this.sendRemoteSnooze = (Button) findViewById(2131296966);
        this.buttonSnooze.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertPlayer.getPlayer().Snooze(SnoozeActivity.this.getApplicationContext(), SnoozeActivity.getTimeFromSnoozeValue(SnoozeActivity.this.snoozeValue.getValue()));
                Intent intent = new Intent(SnoozeActivity.this.getApplicationContext(), (Class<?>) Home.class);
                if (ActiveBgAlert.getOnly() != null) {
                    SnoozeActivity.this.startActivity(intent);
                }
                SnoozeActivity.this.finish();
            }
        });
        showDisableEnableButtons();
        Button button = this.disableAlerts;
        SnoozeType snoozeType = SnoozeType.ALL_ALERTS;
        setOnClickListenerOnDisableButton(button, snoozeType);
        Button button2 = this.disableLowAlerts;
        SnoozeType snoozeType2 = SnoozeType.LOW_ALERTS;
        setOnClickListenerOnDisableButton(button2, snoozeType2);
        Button button3 = this.disableHighAlerts;
        SnoozeType snoozeType3 = SnoozeType.HIGH_ALERTS;
        setOnClickListenerOnDisableButton(button3, snoozeType3);
        setOnClickListenerOnClearDisabledButton(this.clearDisabled, snoozeType);
        setOnClickListenerOnClearDisabledButton(this.clearLowDisabled, snoozeType2);
        setOnClickListenerOnClearDisabledButton(this.clearHighDisabled, snoozeType3);
    }

    private void setOnClickListenerOnClearDisabledButton(Button button, final SnoozeType snoozeType) {
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SnoozeActivity.this.prefs.edit().putLong(snoozeType.getPrefKey(), 0L).apply();
                SnoozeActivity.recheckAlerts();
                SnoozeActivity.this.displayStatus();
                SnoozeActivity.this.showDisableEnableButtons();
            }
        });
    }

    private void setOnClickListenerOnDisableButton(Button button, final SnoozeType snoozeType) {
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final Dialog dialog = new Dialog(SnoozeActivity.this);
                dialog.setTitle(2131755412);
                dialog.setContentView(2131493081);
                Button button2 = (Button) dialog.findViewById(2131296418);
                Button button3 = (Button) dialog.findViewById(2131296429);
                final NumberPicker numberPicker = (NumberPicker) dialog.findViewById(2131296823);
                int length = SnoozeActivity.snoozeValues.length + 1;
                String[] strArr = new String[length];
                int i = 0;
                while (true) {
                    int i2 = length - 1;
                    if (i < i2) {
                        strArr[i] = SnoozeActivity.getNameFromTime(SnoozeActivity.snoozeValues[i]);
                        i++;
                    } else {
                        strArr[i2] = SnoozeActivity.this.getString(2131756941);
                        numberPicker.setMaxValue(i2);
                        numberPicker.setMinValue(0);
                        numberPicker.setDisplayedValues(strArr);
                        numberPicker.setWrapSelectorWheel(false);
                        numberPicker.setValue(SnoozeActivity.getSnoozeLocation(60));
                        button2.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view2) {
                                long timeFromSnoozeValue = numberPicker.getValue() == numberPicker.getMaxValue() ? 5256000L : SnoozeActivity.getTimeFromSnoozeValue(numberPicker.getValue());
                                AnonymousClass3 anonymousClass3 = AnonymousClass3.this;
                                SnoozeActivity.snoozeForType(timeFromSnoozeValue, snoozeType, SnoozeActivity.this.prefs);
                                dialog.dismiss();
                                SnoozeActivity.this.displayStatus();
                                SnoozeActivity.this.showDisableEnableButtons();
                            }
                        });
                        button3.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view2) {
                                dialog.dismiss();
                                SnoozeActivity.this.showDisableEnableButtons();
                            }
                        });
                        dialog.show();
                        return;
                    }
                }
            }
        });
    }

    public static void recheckAlerts() {
        Notifications.start();
        JoH.startService(MissedReadingService.class);
    }

    public void showDisableEnableButtons() {
        if (this.prefs.getLong(SnoozeType.ALL_ALERTS.getPrefKey(), 0L) > new Date().getTime()) {
            this.disableAlerts.setVisibility(8);
            this.clearDisabled.setVisibility(0);
            this.disableLowAlerts.setVisibility(8);
            this.clearLowDisabled.setVisibility(8);
            this.disableHighAlerts.setVisibility(8);
            this.clearHighDisabled.setVisibility(8);
            return;
        }
        this.clearDisabled.setVisibility(8);
        this.disableAlerts.setVisibility(0);
        if (this.prefs.getLong(SnoozeType.LOW_ALERTS.getPrefKey(), 0L) > new Date().getTime()) {
            this.disableLowAlerts.setVisibility(8);
            this.clearLowDisabled.setVisibility(0);
        } else {
            this.disableLowAlerts.setVisibility(0);
            this.clearLowDisabled.setVisibility(8);
        }
        if (this.prefs.getLong(SnoozeType.HIGH_ALERTS.getPrefKey(), 0L) > new Date().getTime()) {
            this.disableHighAlerts.setVisibility(8);
            this.clearHighDisabled.setVisibility(0);
        } else {
            this.disableHighAlerts.setVisibility(0);
            this.clearHighDisabled.setVisibility(8);
        }
    }

    void displayStatus() {
        ActiveBgAlert only = ActiveBgAlert.getOnly();
        AlertType alertTypegetOnly = ActiveBgAlert.alertTypegetOnly();
        if (only == null && alertTypegetOnly != null) {
            UserError.Log.wtf(TAG, "ERRRO displayStatus: aba == null, but activeBgAlert != null exiting...");
            return;
        }
        if (only != null && alertTypegetOnly == null) {
            UserError.Log.wtf(TAG, "ERRRO displayStatus: aba != null, but activeBgAlert == null exiting...");
            return;
        }
        long time = new Date().getTime();
        if (alertTypegetOnly == null) {
            this.sendRemoteSnooze.setVisibility(Pref.getBooleanDefaultFalse("send_snooze_to_remote") ? 0 : 8);
            if (this.prefs.getLong(SnoozeType.ALL_ALERTS.getPrefKey(), 0L) > time || (this.prefs.getLong(SnoozeType.LOW_ALERTS.getPrefKey(), 0L) > time && this.prefs.getLong(SnoozeType.HIGH_ALERTS.getPrefKey(), 0L) > time)) {
                status = "";
            } else {
                status = getString(2131755901);
            }
            this.buttonSnooze.setVisibility(8);
            this.snoozeValue.setVisibility(8);
        } else {
            this.sendRemoteSnooze.setVisibility(8);
            if (!only.ready_to_alarm()) {
                status = MessageFormat.format("Active alert exists named \"{0}\" {1,choice,0#Alert will rerise at|1#Alert snoozed until} {2,time} ({3} minutes left)", alertTypegetOnly.name, Integer.valueOf(only.is_snoozed ? 1 : 0), new Date(only.next_alert_at.longValue()), Long.valueOf((only.next_alert_at.longValue() - time) / 60000));
            } else {
                status = getString(2131755074) + " \"" + alertTypegetOnly.name + "\" " + getString(2131755243);
            }
            SetSnoozePickerValues(this.snoozeValue, alertTypegetOnly.above, alertTypegetOnly.default_snooze);
        }
        SharedPreferences sharedPreferences = this.prefs;
        SnoozeType snoozeType = SnoozeType.ALL_ALERTS;
        if (sharedPreferences.getLong(snoozeType.getPrefKey(), 0L) > time) {
            Object[] objArr = new Object[2];
            objArr[0] = Integer.valueOf(this.prefs.getLong(snoozeType.getPrefKey(), 0L) > time + 283824000000L ? 1 : 0);
            objArr[1] = new Date(this.prefs.getLong(snoozeType.getPrefKey(), 0L));
            status = getString(2131755121) + MessageFormat.format("{0,choice,0#{1,time}|1#you re-enable}", objArr);
        } else {
            SharedPreferences sharedPreferences2 = this.prefs;
            SnoozeType snoozeType2 = SnoozeType.LOW_ALERTS;
            if (sharedPreferences2.getLong(snoozeType2.getPrefKey(), 0L) > time) {
                Object[] objArr2 = new Object[2];
                objArr2[0] = Integer.valueOf(this.prefs.getLong(snoozeType2.getPrefKey(), 0L) > time + 283824000000L ? 1 : 0);
                objArr2[1] = new Date(this.prefs.getLong(snoozeType2.getPrefKey(), 0L));
                status += "\n\n" + getString(2131755781) + MessageFormat.format("{0,choice,0#{1,time}|1#you re-enable}", objArr2);
            }
            SharedPreferences sharedPreferences3 = this.prefs;
            SnoozeType snoozeType3 = SnoozeType.HIGH_ALERTS;
            if (sharedPreferences3.getLong(snoozeType3.getPrefKey(), 0L) > time) {
                Object[] objArr3 = new Object[2];
                objArr3[0] = Integer.valueOf(this.prefs.getLong(snoozeType3.getPrefKey(), 0L) > time + 283824000000L ? 1 : 0);
                objArr3[1] = new Date(this.prefs.getLong(snoozeType3.getPrefKey(), 0L));
                status += "\n\n" + getString(2131755660) + MessageFormat.format("{0,choice,0#{1,time}|1#you re-enable}", objArr3);
            }
        }
        this.alertStatus.setText(status);
    }

    public void setSendRemoteSnoozeOnClick(View view) {
        JoH.static_toast_short(xdrip.gs(2131756184));
        AlertPlayer.getPlayer().Snooze(xdrip.getAppContext(), -1);
    }
}