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);
}
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();
}
}
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();
}
}
}
Aggregations