Search in sources :

Example 1 with ActiveAlertMessage

use of sugar.free.sightparser.applayer.messages.status.ActiveAlertMessage in project SightRemote by TebbeUbben.

the class AlertActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
    String selectedTone = getStringPref(PREF_STRING_ALERT_ALARM_TONE);
    Uri uri = selectedTone == null ? RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE) : Uri.parse(selectedTone);
    ringtone = RingtoneManager.getRingtone(this, uri);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
    layoutParams.screenBrightness = 1.0F;
    getWindow().setAttributes(layoutParams);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    }
    if (savedInstanceState == null)
        alertMessage = (ActiveAlertMessage) SerializationUtils.deserialize(getIntent().getByteArrayExtra("alertMessage"));
    else
        alertMessage = (ActiveAlertMessage) SerializationUtils.deserialize(savedInstanceState.getByteArray("alertMessage"));
    setContentView(getLayoutFile());
    alertCode = findViewById(R.id.alert_code);
    alertTitle = findViewById(R.id.alert_title);
    alertDescription = findViewById(R.id.alert_description);
    mute = findViewById(R.id.mute);
    dismiss = findViewById(R.id.dismiss);
    mute.setOnClickListener(this);
    dismiss.setOnClickListener(this);
    setAlertCode();
    setAlertTitle();
    setAlertDescription();
    update();
    bindService(new Intent(this, AlertService.class), serviceConnection = new ServiceConnection() {

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            alertService = ((AlertService.AlertServiceBinder) service).getService();
            alertService.setAlertActivity(AlertActivity.this);
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            finish();
        }
    }, BIND_AUTO_CREATE);
}
Also used : ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) ActiveAlertMessage(sugar.free.sightparser.applayer.messages.status.ActiveAlertMessage) AlertService(sugar.free.sightremote.services.AlertService) Intent(android.content.Intent) ComponentName(android.content.ComponentName) Uri(android.net.Uri) WindowManager(android.view.WindowManager)

Example 2 with ActiveAlertMessage

use of sugar.free.sightparser.applayer.messages.status.ActiveAlertMessage in project SightRemote by TebbeUbben.

the class AlertService method onStatusChange.

@Override
public void onStatusChange(Status status) {
    if (status == Status.CONNECTED) {
        if (fetchTimer != null)
            return;
        fetchTimer = new Timer(false);
        fetchTimer.schedule(new TimerTask() {

            @Override
            public void run() {
                new SingleMessageTaskRunner(serviceConnector, new ActiveAlertMessage()).fetch(AlertService.this);
            }
        }, 0, 2000);
    } else {
        if (alertActivity != null)
            alertActivity.finish();
        if (fetchTimer != null) {
            fetchTimer.cancel();
            fetchTimer = null;
        }
        serviceConnector.disconnect();
    }
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) ActiveAlertMessage(sugar.free.sightparser.applayer.messages.status.ActiveAlertMessage) SingleMessageTaskRunner(sugar.free.sightparser.handling.SingleMessageTaskRunner)

Example 3 with ActiveAlertMessage

use of sugar.free.sightparser.applayer.messages.status.ActiveAlertMessage in project SightRemote by TebbeUbben.

the class AlertService method onResult.

@Override
public void onResult(Object result) {
    if (result instanceof ActiveAlertMessage) {
        ActiveAlertMessage activeAlertMessage = (ActiveAlertMessage) result;
        if (activeAlertMessage.getAlert() instanceof Error7ElectronicError) {
            serviceConnector.disconnect();
            return;
        }
        Alert alert = activeAlertMessage.getAlert();
        if (alert == null) {
            serviceConnector.disconnect();
            return;
        } else
            serviceConnector.connect();
        if (latestId != activeAlertMessage.getAlertID()) {
            if (alertActivity != null)
                alertActivity.finish();
            if (activeAlertMessage.getAlertStatus() == AlertStatus.MUTED)
                return;
            latestId = activeAlertMessage.getAlertID();
            Intent intent = new Intent(this, AlertActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.putExtra("alertMessage", SerializationUtils.serialize(activeAlertMessage));
            startActivity(intent);
            Answers.getInstance().logCustom(new CustomEvent("Active Alert").putCustomAttribute("Alert", alert.getClass().getSimpleName()));
        } else if (alertActivity != null) {
            alertActivity.setAlertMessage(activeAlertMessage);
            alertActivity.update();
        }
    }
}
Also used : CustomEvent(com.crashlytics.android.answers.CustomEvent) ActiveAlertMessage(sugar.free.sightparser.applayer.messages.status.ActiveAlertMessage) Alert(sugar.free.sightparser.applayer.descriptors.alerts.Alert) Intent(android.content.Intent) Error7ElectronicError(sugar.free.sightparser.applayer.descriptors.alerts.Error7ElectronicError)

Aggregations

ActiveAlertMessage (sugar.free.sightparser.applayer.messages.status.ActiveAlertMessage)3 Intent (android.content.Intent)2 ComponentName (android.content.ComponentName)1 ServiceConnection (android.content.ServiceConnection)1 Uri (android.net.Uri)1 IBinder (android.os.IBinder)1 WindowManager (android.view.WindowManager)1 CustomEvent (com.crashlytics.android.answers.CustomEvent)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 Alert (sugar.free.sightparser.applayer.descriptors.alerts.Alert)1 Error7ElectronicError (sugar.free.sightparser.applayer.descriptors.alerts.Error7ElectronicError)1 SingleMessageTaskRunner (sugar.free.sightparser.handling.SingleMessageTaskRunner)1 AlertService (sugar.free.sightremote.services.AlertService)1