Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display solution status in notification #37

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added res/drawable-xxhdpi/solution_fix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xxhdpi/solution_float.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xxhdpi/solution_none.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xxhdpi/solution_single.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 26 additions & 25 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<string name="menu_map_mode_geoportail_orthoimages">Geoportail aerial</string>
<string name="local_service_started">Local service started</string>
<string name="local_service_stopped">Local service stopped</string>
<string name="local_service_notification_content">%s since %s</string>
<string name="local_service_label">RtkGps</string>
<string name="sky_plot_north">N</string>
<string name="sky_plot_west">W</string>
Expand All @@ -52,7 +53,7 @@
<string name="navdraw_item_processing_options">Processing options</string>
<string name="navdraw_item_solution_options">Solution options</string>
<string name="navdraw_item_ntripcaster_options">Caster options</string>

<string-array name="rtk_server_receiver">
<item>Rover</item>
<item>Base</item>
Expand Down Expand Up @@ -130,7 +131,7 @@
<item>b:</item>
<item>height:</item>
</string-array>

<!-- PMODE_XXX positioning mode -->
<string name="pmode_single">Single</string>
<string name="pmode_dgps">DGPS/DGNSS</string>
Expand Down Expand Up @@ -168,7 +169,7 @@
<string name="solq_ppp">PPP</string>
<string name="solq_dr">Dead reckoning</string>
<string name="solq_internal">Internal</string>

<!-- SOLF_XXX Solution Format -->
<string name="solf_llh">Lat/Long/Height</string>
<string name="solf_xyz">X/Y/Z — ECEF</string>
Expand Down Expand Up @@ -261,7 +262,7 @@
<string name="stapos_rinex_hdr">Rinex header</string>
<string name="stapos_rtcm_pos">RTCM Antenna position</string>


<!-- Procession options -->
<string name="procopt_category_processing_options_1">Processing options 1</string>
<string name="procopt_category_solution_options">Solution options</string>
Expand Down Expand Up @@ -327,7 +328,7 @@
<item>35</item>
<item>40</item>
</string-array>

<string name="procopt_ambiguity_resolution_title">GPS Integer ambiguity resolution</string>
<string name="procopt_ambiguity_resolution_dialog_title">GPS Integer ambiguity resolution</string>
<string-array name="procopt_ambiguity_resolution_entries">
Expand Down Expand Up @@ -532,11 +533,11 @@
<item>30</item>
<item>60</item>
</string-array>

<!-- Output header -->
<string name="solopt_output_header_title">Output header</string>
<string name="solopt_output_header_summary">Set whether the header is output or not</string>

<!-- Output mocklocation -->
<string name="solopt_output_mocklocation_title">Output GPS mock locations</string>
<string name="solopt_output_mocklocation_summary">Set if solution is sent to other applications like the internal GPS</string>
Expand All @@ -553,7 +554,7 @@
<string name="earth_tide_correction_off">OFF</string>
<string name="earth_tide_correction_solid">Solid</string>
<string name="earth_tide_correction_solid_otl_pole">Solid, ocean, pole</string>

<string-array name="solopt_lat_lon_format_entries">
<item>ddd.dddddddd : Degree</item>
<item>ddd mm ss.sss : Degree minute second</item>
Expand Down Expand Up @@ -627,7 +628,7 @@
<string name="solopt_output_customproj4_default">+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs</string>
<string name="solopt_output_testmode_title">Enable test mode</string>
<string name="solopt_output_testmode_summary">If this is enabled and Rover/Base/Correction are off, it runs in a special test mode with positions coming from internal GPS. Obviously no algorithm from RTKLIB can work</string>

<!-- Input streams settings -->
<string name="streams_settings_type_title">Type</string>
<string name="streams_settings_format_title">Format</string>
Expand All @@ -644,10 +645,10 @@
<string name="input_streams_settings_receiver_option_title">Receiver option</string>
<string name="input_streams_settings_transmit_gpgga_to_base_title">Transmit GPGGA to Base Station</string>
<string name="input_streams_settings_transmit_gpgga_lat_title">Latitude</string>
<string name="input_streams_settings_transmit_gpgga_lon_title">Longitude</string>
<string name="input_streams_settings_transmit_gpgga_lon_title">Longitude</string>
<string name="input_streams_setting_antenna_title">Antenna</string>
<string name="input_streams_setting_antenna_summary">Antenna official IGS name (for phase center variation)</string>

<string-array name="input_streams_settings_transmit_gpgga_entries">
<item>OFF</item>
<item>Latitude/Longitude</item>
Expand All @@ -658,8 +659,8 @@
<item>1</item>
<item>2</item>
</string-array>


<!-- Output stream settings -->
<string name="output_streams_settings_enable_solution1_title">Enable Solution 1</string>
<string name="output_streams_settings_enable_solution2_title">Enable Solution 2</string>
Expand All @@ -668,15 +669,15 @@
<string name="output_streams_settings_solution2_tab_title">Solution 2</string>
<string name="output_streams_settings_gpxtrace_tab_title">GPX Trace</string>


<!-- Log stream settings -->
<string name="log_streams_settings_enable_rover_title">Log rover</string>
<string name="log_streams_settings_enable_base_title">Log base </string>
<string name="log_streams_settings_enable_correction_title">Log correction</string>
<string name="log_stream_settings_rover_tab_title">Log Rover</string>
<string name="log_stream_settings_base_tab_title">Log Base</string>
<string name="log_stream_settings_correction_tab_title">Log Correction</string>

<!-- NTRIP client stream preferences -->
<string name="ntrip_client_dialog_title">NTRIP client settings</string>
<string name="ntrip_client_host_title">Host</string>
Expand All @@ -703,15 +704,15 @@

<!-- File stream preferences -->
<string name="file_dialog_title">File settings</string>

<!-- Bluetooth stream preferences -->
<string name="bluetooth_dialog_title">Bluetooth receiver settings</string>
<string name="bluetooth_device_not_selected">device not selected</string>
<string name="bluetooth_disabled_summary">Turn on Bluetooth and select the receiver</string>
<string name="bluetooth_device_address_title">Bluetooth device</string>
<string name="bluetooth_system_settings_title">Bluetooth system settings</string>
<string name="bluetooth_system_settings_summary">Display system Bluetooth settings screen</string>

<string name="bluetooth_connected">Bluetooth connected</string>
<string name="bluetooth_connection_lost">Bluetooth connection lost</string>

Expand Down Expand Up @@ -744,10 +745,10 @@
</string-array>

<!-- USB stream preferences -->

<string name="usb_connected">USB connected</string>
<string name="usb_connection_lost">USB connection lost</string>

<string name="usb_dialog_title">USB receiver settings</string>
<string name="usb_device_baudrate_title">Baudrate</string>
<string-array name="usb_device_baudrate_entries">
Expand Down Expand Up @@ -794,30 +795,30 @@
<item>1</item>
<item>2</item>
</string-array>

<!-- Startup/shutdown commands preference widget -->
<string name="send_commands_at_startup">Send commands at startup</string>
<string name="send_commands_at_shutdown">Send commands at shutdown</string>
<string name="commands_at_startup">Commands at startup</string>
<string name="commands_at_shutdown">Commands at shutdown</string>
<string name="load_startup_shutdown_commands">Load</string>
<string name="load_startup_shutdown_dialog_title">Select file</string>

<!-- Rover/base position -->
<string name="station_position_format_llh">Lat/Lon/Height (deg/m)</string>
<string name="station_position_format_llh_dms">Lat/Lon/Height (dms/m)</string>
<string name="station_position_format_ecef">X/Y/Z — ECEF</string>
<string name="station_position_for_fixed_mode">For fixed mode</string>
<string name="station_position_for_relative_mode">For relative mode</string>

<!-- StatusView -->
<string name="status_view_snr">SNR Rover/Base</string>
<string name="status_view_snr_l1">SNR Rover/Base L1</string>
<string name="status_view_snr_l2">SNR Rover/Base L2</string>
<string name="status_view_snr_l5">SNR Rover/Base L5</string>
<string name="status_view_skyplot_rover_l1">Skyplot Rover L1</string>
<string name="status_view_skyplot_rover_l2">Skyplot Rover L2</string>
<string name="status_view_skyplot_rover_l5">Skyplot Rover L5</string>
<string name="status_view_skyplot_rover_l5">Skyplot Rover L5</string>
<string name="status_view_skyplot_base_l1">Skyplot Base L1</string>
<string name="status_view_skyplot_base_l2">Skyplot Base L2</string>
<string name="status_view_skyplot_base_l5">Skyplot Base L5</string>
Expand All @@ -830,12 +831,12 @@
<string name="tools_download_egm2008_m25_geoid">Install EGM 2008 2.5\' Geoid (135MB)</string>
<string name="tools_download_egm2008_m10_geoid">Install EGM 2008 1.0\' Geoid (825MB)</string>
<string name="tools_download_egm96_m150_geoid">Install EGM 96 15\' Geoid (2MB)</string>

<string name="changelog_full_title">Change Log</string>
<string name="changelog_title">What\'s New</string>
<string name="changelog_ok_button">OK</string>
<string name="changelog_show_full">more…</string>

<string name="ntripcaster_options_enabled_summary">Enable experimental NTRIP Caster</string>
<string name="ntripcaster_options_enabled_title">NTRIP Caster</string>
<string name="ntripcaster_options_brutal_ending_summary">Ending NTRIP Caster will also shutown RTKGPS+, it is safer for being sure all connections are closed.</string>
Expand Down
59 changes: 50 additions & 9 deletions src/gpsplus/rtkgps/RtkNaviService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.util.Log;
import android.widget.Toast;
import butterknife.BindString;
Expand Down Expand Up @@ -62,13 +63,16 @@
import gpsplus.rtklib.Solution;
import gpsplus.rtklib.constants.EphemerisOption;
import gpsplus.rtklib.constants.GeoidModel;
import gpsplus.rtklib.constants.SolutionStatus;
import gpsplus.rtklib.constants.StreamType;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class RtkNaviService extends IntentService implements LocationListener {
Expand Down Expand Up @@ -131,7 +135,12 @@ public RtkNaviService() {
private static final String MM_MAP_HEADER = "COMPD_CS[\"WGS 84\",GEOGCS[\"\",DATUM[\"WGS 84\",SPHEROID[\"WGS 84\",6378137,298.257223563],TOWGS84[0,0,0,0,0,0,0]],PRIMEM[\"Greenwich\",0],UNIT[\"Degrees\",0.0174532925199433],AXIS[\"Long\",East],AXIS[\"Lat\",North]],VERT_CS[\"\",VERT_DATUM[\"Ellipsoid\",2002],UNIT[\"Meters\",1],AXIS[\"Height\",Up]]]\r\n";
private static final String GPS_PROVIDER = LocationManager.GPS_PROVIDER;
private boolean mHavePoint = false;
private int NOTIFICATION = R.string.local_service_started;
private static final int NOTIFICATION = R.string.local_service_started;
private static NotificationCompat.Builder notificationBuilder;
private static NotificationManagerCompat notificationManager;
private static SolutionStatus previousSolutionStatus;
private static Context context;

private RtkCommon rtkCommon;

// Binder given to clients
Expand Down Expand Up @@ -160,10 +169,10 @@ public RtkNaviService() {
@Override
public void onCreate() {
super.onCreate();
context = this.getBaseContext();

final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mCpuLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);

}

@Override
Expand Down Expand Up @@ -389,8 +398,11 @@ public void processStart() {

mCpuLock.acquire();

Notification notification = createForegroundNotification();
startForeground(NOTIFICATION, notification);
notificationManager = NotificationManagerCompat.from(this);
notificationBuilder = createForegroundNotificationBuilder();
previousSolutionStatus = SolutionStatus.NONE;
setNotificationSolutionStatus(previousSolutionStatus);
startForeground(NOTIFICATION, notificationBuilder.build());

SharedPreferences prefs = this.getBaseContext().getSharedPreferences(SolutionOutputSettingsFragment.SHARED_PREFS_NAME, 0);
mBoolMockLocationsPref = prefs.getBoolean(SolutionOutputSettingsFragment.KEY_OUTPUT_MOCK_LOCATION, false);
Expand Down Expand Up @@ -437,7 +449,6 @@ public void processStart() {
mBoolIsRunning = true;
}


private void processStop() {
mBoolIsRunning = false;
mbStarted = false;
Expand Down Expand Up @@ -628,7 +639,7 @@ public void onDestroy() {
}

@SuppressWarnings("deprecation")
private Notification createForegroundNotification() {
private NotificationCompat.Builder createForegroundNotificationBuilder() {
CharSequence text = getText(R.string.local_service_started);

// The PendingIntent to launch our activity if the user selects this
Expand All @@ -645,7 +656,7 @@ private Notification createForegroundNotification() {
builder.setNumber(100);
builder.setAutoCancel(false);

return builder.build();
return builder;
}

private class BluetoothCallbacks implements BluetoothToRtklib.Callbacks {
Expand Down Expand Up @@ -831,6 +842,34 @@ private void stopUsb() {
}
}

private static void setNotificationSolutionStatus(SolutionStatus solutionStatus) {
int resId = solutionStatus.getNameResId();
String solutionStatusText = context.getString(resId);
String contentText = String.format(
context.getString(R.string.local_service_notification_content),
solutionStatusText,
new SimpleDateFormat("HH:mm:ss").format(new Date())
);
notificationBuilder.setContentText(contentText);
notificationBuilder.setSmallIcon(solutionStatus.getIconResId());
}

private static void updateNotification() {
notificationManager.notify(NOTIFICATION, notificationBuilder.build());
}

public static void setNotificationSolutionStatusWithUpdate(SolutionStatus solutionStatus) {
if (
previousSolutionStatus != solutionStatus &&
notificationBuilder != null &&
notificationManager != null
) {
setNotificationSolutionStatus(solutionStatus);
updateNotification();
previousSolutionStatus = solutionStatus;
}
}

/* (non-Javadoc)
* @see android.app.IntentService#onHandleIntent(android.content.Intent)
*/
Expand All @@ -842,10 +881,12 @@ protected void onHandleIntent(Intent arg0) {

{
try {
RtkControlResult result = getRtkStatus(null);
Solution solution = result.getSolution();
SolutionStatus solutionStatus = solution.getSolutionStatus();
setNotificationSolutionStatusWithUpdate(solutionStatus);
if (mBoolMockLocationsPref || mBoolGenerateGPXTrace)
{
RtkControlResult result = getRtkStatus(null);
Solution solution = result.getSolution();
Position3d positionECEF = solution.getPosition();

if (RtkCommon.norm(positionECEF.getValues()) > 0.0)
Expand Down
1 change: 1 addition & 0 deletions src/gpsplus/rtkgps/view/SolutionView.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ public void setStats(RtkControlResult status) {
mSolutionIndicatorView.setStatus(solStatus);
updateCoordinates(status);
updateAgeText(sol);
RtkNaviService.setNotificationSolutionStatusWithUpdate(solStatus);
}

public void setFormat(Format format) {
Expand Down
Loading