Fixed #1
parent
948eb6f5f2
commit
8a0ed40504
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest package="us.keithirwin.tracman"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="us.keithirwin.tracman">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
|
@ -11,23 +11,23 @@
|
|||
<uses-feature android:name="android.hardware.location.gps"/>
|
||||
|
||||
<application
|
||||
android:label="@string/app_name"
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/logo_by"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity android:name=".LoginActivity">
|
||||
<intent-filter android:label="@string/app_name">
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".SettingsActivity"
|
||||
android:label="@string/settings_name"
|
||||
android:parentActivityName=".LoginActivity">
|
||||
|
||||
<!-- Parent activity meta-data to support 4.0 and lower -->
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
|
@ -39,6 +39,7 @@
|
|||
android:exported="false">
|
||||
</service>
|
||||
|
||||
<!--Startup on boot-->
|
||||
<receiver
|
||||
android:name=".BootReceiver"
|
||||
android:enabled="true"
|
||||
|
@ -52,6 +53,15 @@
|
|||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<!--Check for Disconnection-->
|
||||
<receiver
|
||||
android:name=".ConnectionReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -0,0 +1,35 @@
|
|||
package us.keithirwin.tracman;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.util.Log;
|
||||
|
||||
public class ConnectionReceiver extends BroadcastReceiver {
|
||||
private String TAG = "ConnectionReceiver";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.d(TAG,"onReceive() called");
|
||||
|
||||
// Get connection information
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
|
||||
|
||||
// Prepare intent
|
||||
Intent locationServiceIntent = new Intent(context, LocationService.class);
|
||||
|
||||
// Check connection
|
||||
if (networkInfo!=null) {
|
||||
Log.d(TAG, "Connected");
|
||||
context.startService(locationServiceIntent);
|
||||
}
|
||||
else {
|
||||
Log.d(TAG,"Disconnected");
|
||||
context.stopService(locationServiceIntent);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -42,6 +42,9 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
|||
GoogleApiClient.OnConnectionFailedListener, LocationListener {
|
||||
public LocationService() {}
|
||||
private String TAG = "LocationService";
|
||||
final int ICON_ON = 2;
|
||||
final int ICON_HALF = 1;
|
||||
final int ICON_OFF = 0;
|
||||
final String SERVER_ADDRESS = "https://dev.tracman.org";
|
||||
|
||||
private Socket socket;
|
||||
|
@ -64,6 +67,8 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
|||
private NotificationManager mNotificationManager;
|
||||
private final NotificationCompat.Builder mNotificationBuilder = new NotificationCompat.Builder(this);
|
||||
private void setupNotifications(Boolean persist) {
|
||||
Log.d(TAG,"setupNotification() called");
|
||||
|
||||
if (mNotificationManager == null) {
|
||||
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
}
|
||||
|
@ -73,21 +78,28 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
|||
0);
|
||||
mNotificationBuilder
|
||||
.setPriority(-1)
|
||||
.setSmallIcon(R.drawable.logo_white)
|
||||
.setSmallIcon(R.drawable.logo_dark)
|
||||
.setCategory(NotificationCompat.CATEGORY_SERVICE)
|
||||
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||
.setContentTitle(getText(R.string.app_name))
|
||||
.setContentIntent(notificationIntent)
|
||||
.setOngoing(persist);
|
||||
}
|
||||
private void showNotification(CharSequence text, Boolean active) {
|
||||
private void showNotification(CharSequence text, int icon) {
|
||||
Log.d(TAG,"showNotification() called");
|
||||
mNotificationBuilder
|
||||
.setTicker(text)
|
||||
.setContentText(text);
|
||||
if (active) {
|
||||
switch (icon) {
|
||||
case ICON_ON:
|
||||
mNotificationBuilder.setSmallIcon(R.drawable.logo_white);
|
||||
} else {
|
||||
break;
|
||||
case ICON_HALF:
|
||||
mNotificationBuilder.setSmallIcon(R.drawable.logo_trans);
|
||||
break;
|
||||
case ICON_OFF:
|
||||
mNotificationBuilder.setSmallIcon(R.drawable.logo_dark);
|
||||
break;
|
||||
}
|
||||
if (mNotificationManager != null) {
|
||||
mNotificationManager.notify(1, mNotificationBuilder.build());
|
||||
|
@ -111,7 +123,7 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
|||
sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
setupNotifications(true);
|
||||
showNotification(getText(R.string.connecting), false);
|
||||
showNotification(getText(R.string.notify_connecting), ICON_OFF);
|
||||
Log.d(TAG, "Notification set up");
|
||||
|
||||
buildGoogleApiClient();
|
||||
|
@ -134,7 +146,7 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
|||
opts.secure = true;
|
||||
socket = IO.socket(SERVER_ADDRESS, opts);
|
||||
|
||||
showNotification(getText(R.string.connected), false);
|
||||
showNotification(getText(R.string.notify_connected), ICON_HALF);
|
||||
|
||||
// Log errors
|
||||
socket.io().on(Manager.EVENT_TRANSPORT, new Emitter.Listener() {
|
||||
|
@ -145,7 +157,7 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
|||
@Override
|
||||
public void call(Object... args) {
|
||||
Exception e = (Exception) args[0];
|
||||
Log.e(TAG, "Transport error " + e);
|
||||
Log.e(TAG, "Transport error: " + e);
|
||||
e.printStackTrace();
|
||||
e.getCause().printStackTrace();
|
||||
}
|
||||
|
@ -166,7 +178,7 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
|||
socket.connect();
|
||||
|
||||
} catch (URISyntaxException e) {
|
||||
showNotification(getText(R.string.server_connection_error), false);
|
||||
showNotification(getText(R.string.server_connection_error), ICON_OFF);
|
||||
Log.e(TAG, "Failed to connect to sockets server " + SERVER_ADDRESS, e);
|
||||
}
|
||||
|
||||
|
@ -234,7 +246,7 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
|||
|
||||
mLocationRequest = LocationRequest.create();
|
||||
connectLocationUpdates(getIntervalSetting(), getPrioritySetting());
|
||||
showNotification(getString(R.string.realtime_updates), true);
|
||||
showNotification(getString(R.string.occasional_updates), ICON_HALF);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -245,7 +257,7 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
|||
@Override
|
||||
public void onConnectionFailed(ConnectionResult connectionResult) {
|
||||
Log.e(TAG, "onConnectionFailed: " + connectionResult);
|
||||
showNotification(getText(R.string.google_connection_error), false);
|
||||
showNotification(getText(R.string.google_connection_error), ICON_OFF);
|
||||
buildGoogleApiClient();
|
||||
}
|
||||
|
||||
|
@ -255,11 +267,11 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
|||
if (args[0].toString().equals("true")) {
|
||||
Log.d(TAG, "Activating realtime updates");
|
||||
connectLocationUpdates(getIntervalSetting(), getPrioritySetting());
|
||||
showNotification(getString(R.string.realtime_updates), true);
|
||||
showNotification(getString(R.string.realtime_updates), ICON_ON);
|
||||
} else {
|
||||
Log.d(TAG, "Deactivating realtime updates");
|
||||
connectLocationUpdates(300, LocationRequest.PRIORITY_NO_POWER);
|
||||
showNotification(getString(R.string.occasional_updates), false);
|
||||
showNotification(getString(R.string.occasional_updates), ICON_HALF);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -293,7 +305,7 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
|||
@Override
|
||||
public void onConnectionSuspended(int i) {
|
||||
Log.d(TAG, "onConnectionSuspended called");
|
||||
showNotification(getText(R.string.google_connection_error), false);
|
||||
showNotification(getText(R.string.google_connection_error), ICON_OFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -312,7 +324,7 @@ public class LocationService extends Service implements GoogleApiClient.Connecti
|
|||
Log.d(TAG, "LowPowerReceiver deactivated");
|
||||
|
||||
setupNotifications(false);
|
||||
showNotification(getText(R.string.disconnected), false);
|
||||
showNotification(getText(R.string.disconnected), ICON_OFF);
|
||||
Log.d(TAG, "Notification changed");
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
After Width: | Height: | Size: 878 B |
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.6 KiB |
Binary file not shown.
After Width: | Height: | Size: 4.0 KiB |
|
@ -4,8 +4,6 @@
|
|||
<string name="about_name">Über</string>
|
||||
<string name="broadcast_disabled">Sendungen deaktiviert</string>
|
||||
<string name="bugs_name">Problembericht</string>
|
||||
<string name="connected">Verbindung festgestellt</string>
|
||||
<string name="connecting">verbindet…</string>
|
||||
<string name="disconnected">Verbindung unterbrochen</string>
|
||||
<string name="google_connection_error">FEHLER: Könnte nicht zum Google API Server verbinden. </string>
|
||||
<string name="help_name">Hilfe</string>
|
||||
|
@ -49,9 +47,11 @@
|
|||
</string-array>
|
||||
<string name="pref_title_gps_broadcast">Sendungen einschalten</string>
|
||||
<string name="pref_title_broadcast_priority">Aktualisierung Vorrang</string>
|
||||
<string name="not_connected">Kein Internet Zugang</string>
|
||||
<string name="login_forgot_password"><a href="https://tracman.org/login/forgot">Passwort vergessen?</a></string>
|
||||
<string name="login_button_text">Einloggen</string>
|
||||
<string name="email">Email</string>
|
||||
<string name="password">Passwort</string>
|
||||
<string name="notify_connecting">verbindet…</string>
|
||||
<string name="notify_disabled">Aktualisiert nicht</string>
|
||||
<string name="notify_connected">Verbindung festgestellt</string>
|
||||
</resources>
|
|
@ -2,10 +2,8 @@
|
|||
<resources>
|
||||
<string name="about_back_button">Atras</string>
|
||||
<string name="about_name">Info</string>
|
||||
<string name="connecting">conectando…</string>
|
||||
<string name="loading">Cargando…</string>
|
||||
<string name="disconnected">Conexión perdida</string>
|
||||
<string name="connected">Conexión establecida</string>
|
||||
<string name="bugs_name">Informe de error</string>
|
||||
<string name="pref_header_general">Configuración principales</string>
|
||||
<string name="settings_name">Configuración</string>
|
||||
|
@ -47,10 +45,13 @@
|
|||
<item>Ciudad</item>
|
||||
<item>Sin energía</item>
|
||||
</string-array>
|
||||
<string name="pref_title_gps_broadcast">Encender transmisiónes</string> <string name="pref_broadcast_category_title">Actualizaciones de ubicación</string>
|
||||
<string name="not_connected">Sin conexión a Internet</string>
|
||||
<string name="pref_title_gps_broadcast">Encender transmisiónes</string>
|
||||
<string name="pref_broadcast_category_title">Actualizaciones de ubicación</string>
|
||||
<string name="login_forgot_password"><a href="https://tracman.org/login/forgot">Olividé su contrasena?</a></string>
|
||||
<string name="login_button_text">Inciar session</string>
|
||||
<string name="email">email</string>
|
||||
<string name="password">contrasena</string>
|
||||
<string name="notify_connecting">conectando…</string>
|
||||
<string name="notify_disabled">No se actualiza</string>
|
||||
<string name="notify_connected">Conexión establecida</string>
|
||||
</resources>
|
|
@ -16,13 +16,10 @@
|
|||
<string name="server_connection_error">ERROR: Unable to connect to Tracman server. </string>
|
||||
|
||||
<!-- Strings related to notifications -->
|
||||
<string name="connecting">Connecting… </string>
|
||||
<string name="connected">Connection established</string>
|
||||
<string name="disconnected">Disconnected</string>
|
||||
<string name="realtime_updates">Sending realtime updates</string>
|
||||
<string name="occasional_updates">Sending occasional updates</string>
|
||||
<string name="broadcast_disabled">Broadcast disabled</string>
|
||||
<string name="not_connected">No internet connection</string>
|
||||
|
||||
<!-- Strings related to Settings -->
|
||||
<string name="settings_name">Settings</string>
|
||||
|
@ -102,5 +99,8 @@
|
|||
<string name="login_button_text">Login</string>
|
||||
<string name="email">email</string>
|
||||
<string name="password">password</string>
|
||||
<string name="notify_disabled">Not sending updates</string>
|
||||
<string name="notify_connecting">"Connecting… "</string>
|
||||
<string name="notify_connected">Connection established</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue