HypoAlarm/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/AlarmAlertActivity.java

103 lines
3.1 KiB
Java

package za.org.treehouse.hypoalarm;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import net.frakbot.glowpadbackport.GlowPadView;
public class AlarmAlertActivity extends Activity {
public static Activity alertActivity;
@Override
protected void onDestroy() {
super.onDestroy();
alertActivity = null;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Self-reference so we can run finish() from other classes
alertActivity = this;
requestWindowFeature(Window.FEATURE_NO_TITLE);
final Window window = getWindow();
// Set to use the full screen
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
| WindowManager.LayoutParams.FLAG_FULLSCREEN
);
if (Build.VERSION.SDK_INT >= 11) {
window.getDecorView().
setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
}
setContentView(R.layout.alarm_alert);
Intent notifyIntent = new Intent(getApplicationContext(), AlarmNotify.class);
// Disable any current notifications (if we're snoozing)
stopService(notifyIntent);
}
@Override
public void onStart() {
super.onStart();
final GlowPadView cancelGlowPad = (GlowPadView) findViewById(R.id.cancel_glowpad);
cancelGlowPad.setOnTriggerListener(new GlowPadView.OnTriggerListener() {
@Override
public void onGrabbed(View v, int handle) {
// Do nothing
}
@Override
public void onReleased(View v, int handle) {
// Do nothing
}
@Override
public void onTrigger(View v, int target) {
// if (target == "")
AlarmService.dismissAlarm(alertActivity);
}
@Override
public void onGrabbedStateChange(View v, int handle) {
// Do nothing
}
@Override
public void onFinishFinalAnimation() {
// Do nothing
}
});
}
/**
* Handle the user pressing the back/return and home buttons
*/
@Override
public void onBackPressed() {
if (!AlarmService.alarmStatus.contentEquals(AlarmService.ALARM_SNOOZE_RUNNING)) {
AlarmService.setAlarmStatus(AlarmService.ALARM_IGNORED);
}
AlarmService.snoozeAlarm(this);
}
public void onUserLeaveHint() {
if (!AlarmService.alarmStatus.contentEquals(AlarmService.ALARM_SNOOZE_RUNNING)) {
AlarmService.setAlarmStatus(AlarmService.ALARM_IGNORED);
}
AlarmService.snoozeAlarm(this);
}
}