launcher icon / sms / manager on boot

This commit is contained in:
Senad Uka
2016-11-19 08:03:54 +01:00
parent f937f0ac2c
commit d17fd8f940
13 changed files with 64 additions and 45 deletions

View File

@@ -4,7 +4,8 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
@@ -19,40 +20,51 @@
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="agrar.zoblak.com" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="agrar.zoblak.com" />
</intent-filter>
</activity>
<service
android:name=".AlarmPollingService"
android:exported="false" />
<service
android:name=".SoundPlayingService"
android:exported="false" />
<receiver
android:name="PeriodicalPingReceiver"
android:name=".PeriodicalPingReceiver"
android:enabled="true"
android:exported="true" />
<activity
android:screenOrientation="portrait"
android:name=".SettingsActivity"
android:label="@string/title_activity_settings"
android:parentActivityName=".MainScreen">
android:parentActivityName=".MainScreen"
android:screenOrientation="portrait">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.zoblak.farmalarm.MainScreen" />
</activity>
<receiver
android:name=".BootBroadcastReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>

View File

@@ -0,0 +1,15 @@
package com.zoblak.farmalarm;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class BootBroadcastReceiver extends BroadcastReceiver {
public BootBroadcastReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
MainScreen.setupAlarmManager(context);
}
}

View File

@@ -20,8 +20,7 @@ import java.lang.System;
public class MainScreen extends AppCompatActivity {
private AlarmManager alarmMgr;
private PendingIntent alarmIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -29,24 +28,25 @@ public class MainScreen extends AppCompatActivity {
setContentView(R.layout.activity_main_screen);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
Intent intent = new Intent(this, PeriodicalPingReceiver.class);
alarmIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
setupAlarmManager(this);
int PERIOD_IN_MS = 5 * 60 * 1000; // 5 minutes
alarmMgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
}
public static void setupAlarmManager(Context context) {
AlarmManager alarmMgr;
PendingIntent alarmIntent;
Intent intent = new Intent(context, PeriodicalPingReceiver.class);
alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
int PERIOD_IN_MS = 2 * 60 * 1000; // 2 minutes
alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
// Hopefully your alarm will have a lower frequency than this!
alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis(),

View File

@@ -23,12 +23,4 @@
<include layout="@layout/content_main_screen" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -1,7 +1,6 @@
<template name="alarm">
<div class="hello">
<h1> Temperatura </h1>
<div class="jumbotron text-center center-block" >
{{#with state}}
{{#if alarmTriggered}}

View File

@@ -11,7 +11,7 @@
}
.huge_text {
font-size: 3em;
font-size: 2.5em;
}
@media all and (orientation: portrait) {
@@ -32,14 +32,14 @@
@media all and (orientation: portrait) {
#alarm_image {
width: 90%;
width: 70%;
cursor: pointer;
}
}
@media all and (orientation: landscape) {
#alarm_image {
width: 40%;
width: 30%;
cursor: pointer;
}
}

View File

@@ -28,6 +28,7 @@ Api.addRoute('sensorData', {
created_at: new Date()
};
SensorData.insert(sensorObject);
reactToAlarmData(this.bodyParams.controllerId);
return [];
}
});

View File

@@ -149,8 +149,8 @@ function saveAlarmSettings(controller_id, minTemperature, maxTemperature, timeou
'$set': {
'config.minTemperature': parseFloat(minTemperature),
'config.maxTemperature': parseFloat(maxTemperature),
'config.timeoutBox': parseInt(timeoutBox),
'config.timeoutPhone': parseInt(timeoutPhone),
'config.timeoutBox': timeoutBox ? parseInt(timeoutBox) : null,
'config.timeoutPhone': timeoutPhone ? parseInt(timeoutPhone) : null,
'config.smsNumbers': smsNumbers,
'config.sms1': smsNumbers[0],
'config.sms2': smsNumbers[1],
@@ -164,7 +164,7 @@ function saveAlarmSettings(controller_id, minTemperature, maxTemperature, timeou
SyncedCron.add({
name: jobName,
schedule: function(parser) {
return parser.text('every 30 seconds');
return parser.text('every 10 seconds');
},
job: function() {
reactToAlarmData(controller_id);
@@ -252,7 +252,7 @@ function soundTheAlarm(controller_id, tooCold, tooHot, boxSilent, phoneSilent) {
};
var smsSent = !!state.state.alarmSmsSent;
var needsToSendSms = !smsSent; // && (boxSilent || phoneSilent);
var needsToSendSms = !smsSent && phoneSilent;
var sendSmsPart = needsToSendSms ? { 'state.alarmSmsSent': true } : {};