Skip to content

Commit

Permalink
Merge pull request #301 from enviroCar/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
dewall committed Jun 7, 2016
2 parents d32f12e + f9c141e commit 384ddbb
Show file tree
Hide file tree
Showing 18 changed files with 263 additions and 106 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ ext {
compileSdkVersion = 23
targetSdkVersion = 23
buildToolsVersion = '23.0.2'
versionCode = 30
versionName = "0.22.1"
versionCode = 31
versionName = "0.22.2"

javaCompileVersion = JavaVersion.VERSION_1_8

Expand Down
4 changes: 2 additions & 2 deletions org.envirocar.app/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
xmlns:android="http://schemas.android.com/apk/res/android"
package="org.envirocar.app"
android:installLocation="internalOnly"
android:versionCode="30"
android:versionName="0.22.1">
android:versionCode="31"
android:versionName="0.22.2">

<uses-sdk
android:minSdkVersion="16"
Expand Down
2 changes: 2 additions & 0 deletions org.envirocar.app/res/values-de/strings_logbook.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
-->
<resources>
<string name="logbook_invalid_input">Ungültige Eingabe</string>

<string name="logbook_my_fuelings_header">Mein Tankstops</string>
<string name="logbook_add_fueling">Tankstop Hinzufügen</string>
<string name="logbook_enter_info">Geben Sie Kilometerstand, getanktes Volumen und Preis ein...</string>
Expand Down
4 changes: 4 additions & 0 deletions org.envirocar.app/res/values-de/strings_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@

<string name="menu_not_logged_in">Nicht Eingeloggt</string>
<string name="menu_not_logged_in_sub">Hier klicken um sich einzuloggen.</string>

<string name="menu_close_envirocar_title">enviroCar Beenden</string>
<string name="menu_close_envirocar_positive">Beenden</string>
<string name="menu_close_envirocar_content">Diese Funktion schließt die Applikation einschließlich aller laufenden Hintergrundsprozesse und Aufzeichnungen.</string>
</resources>
2 changes: 2 additions & 0 deletions org.envirocar.app/res/values/strings_logbook.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
-->
<resources>
<string name="logbook_invalid_input">Invalid input</string>

<string name="logbook_my_fuelings_header">My Fuelings</string>
<string name="logbook_add_fueling">Add Fueling</string>
<string name="logbook_enter_info">Enter milage, volume and price...</string>
Expand Down
4 changes: 4 additions & 0 deletions org.envirocar.app/res/values/strings_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@

<string name="menu_not_logged_in">Not Logged In</string>
<string name="menu_not_logged_in_sub">Click here to log in.</string>

<string name="menu_close_envirocar_title">Shutdown enviroCar</string>
<string name="menu_close_envirocar_positive">Shutdown</string>
<string name="menu_close_envirocar_content">This completely closes the application including all running background services and track recordings.</string>
</resources>
93 changes: 48 additions & 45 deletions org.envirocar.app/src/org/envirocar/app/BaseMainActivity.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/**
* Copyright (C) 2013 - 2015 the enviroCar community
*
* <p>
* This file is part of the enviroCar app.
*
* <p>
* The enviroCar app is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* <p>
* The enviroCar app is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* <p>
* You should have received a copy of the GNU General Public License along
* with the enviroCar app. If not, see http://www.gnu.org/licenses/.
*/
Expand Down Expand Up @@ -75,7 +75,6 @@
import org.envirocar.core.logging.Logger;
import org.envirocar.core.util.Util;
import org.envirocar.core.util.VersionRange;
import org.envirocar.core.utils.ServiceUtils;
import org.envirocar.obd.events.BluetoothServiceStateChangedEvent;
import org.envirocar.obd.service.BluetoothServiceState;
import org.envirocar.remote.DAOProvider;
Expand All @@ -85,6 +84,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import javax.inject.Inject;

Expand Down Expand Up @@ -164,8 +164,7 @@ protected void onCreate(Bundle savedInstanceState) {
boolean noInstantiatedExceptionReceived = false;
try {
super.onCreate(savedInstanceState);
}
catch (IllegalStateException e) {
} catch (IllegalStateException e) {
LOGGER.warn("Trying to reconstruct fragment state. Got Exception", e);
if (e.getMessage().contains("No instantiated fragment for index #")) {
noInstantiatedExceptionReceived = true;
Expand All @@ -185,11 +184,12 @@ protected void onCreate(Bundle savedInstanceState) {
if (noInstantiatedExceptionReceived) {
TrackListPagerFragment pagerFragment = new TrackListPagerFragment();
if (mNavigationView != null && mNavigationView.getMenu() != null) {
MenuItem menuItem = mNavigationView.getMenu().findItem(R.id.menu_nav_drawer_tracklist_new);
MenuItem menuItem = mNavigationView.getMenu().findItem(R.id
.menu_nav_drawer_tracklist_new);
transitToFragment(menuItem, pagerFragment);
}
else {
LOGGER.warn("Could not re-create TrackListPagerFragment: mNavigationView="+ mNavigationView);
} else {
LOGGER.warn("Could not re-create TrackListPagerFragment: mNavigationView=" +
mNavigationView);
}
}

Expand Down Expand Up @@ -231,11 +231,7 @@ protected void onCreate(Bundle savedInstanceState) {
// Subscribe for preference subscriptions. In this case, subscribe for changes to the
// active screen settings.
// TODO
subscriptions.add(PreferencesHandler.getDisplayStaysActiveObservable(this)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(aBoolean -> {
checkKeepScreenOn();
}));
addPreferenceSubscriptions();

errorInformationReceiver = new BroadcastReceiver() {
@Override
Expand Down Expand Up @@ -263,6 +259,30 @@ public void onReceive(Context context, Intent intent) {
resolvePersistentSeenAnnouncements();
}

private void addPreferenceSubscriptions() {
// Keep screen active setting;
subscriptions.add(
PreferencesHandler.getDisplayStaysActiveObservable(this)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(aBoolean -> {
checkKeepScreenOn();
})
);

// Start Background handler
subscriptions.add(
PreferencesHandler.getBackgroundHandlerEnabledObservable(this)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(aBoolean -> {
if (aBoolean) {
SystemStartupService.startService(this);
} else {
SystemStartupService.stopService(this);
}
})
);
}

@Subscribe
public void onReceiveBluetoothStateChangedEvent(BluetoothStateChangedEvent event) {
LOGGER.info(String.format("Received event: %s", event.toString()));
Expand Down Expand Up @@ -514,23 +534,11 @@ private boolean selectDrawerItem(MenuItem menuItem) {
fragment = new SendLogFileFragment();
break;
case R.id.menu_nav_drawer_quit_app:
// new MaterialDialog.Builder(this)
// .title("Test")
// .customView(R.layout.util_currency_input_view, true)
// .positiveText("Okay")
// .callback(new MaterialDialog.ButtonCallback() {
// @Override
// public void onAny(MaterialDialog dialog) {
// super.onAny(dialog);
// }
// })
// .show();
new MaterialDialog.Builder(this)
.title("Shutdown enviroCar")
.positiveText("Shutdown")
.negativeText("Cancel")
.content("This completely closes the application including all running " +
"background services and track recordings.")
.title(getString(R.string.menu_close_envirocar_title))
.positiveText(getString(R.string.menu_close_envirocar_positive))
.negativeText(getString(R.string.cancel))
.content(getString(R.string.menu_close_envirocar_content))
.callback(new MaterialDialog.ButtonCallback() {
@Override
public void onPositive(MaterialDialog dialog) {
Expand Down Expand Up @@ -569,18 +577,13 @@ private void transitToFragment(MenuItem menuItem, Fragment fragment) {
}

private void shutdownEnviroCar() {
SystemStartupService.stopService(this);
OBDConnectionService.stopService(this);

if (ServiceUtils.isServiceRunning(this, OBDConnectionService.class)) {
Intent intent = new Intent(getApplicationContext(), OBDConnectionService.class);
getApplicationContext().stopService(intent);
}
if (ServiceUtils.isServiceRunning(this, SystemStartupService.class)) {
Intent intent = new Intent(getApplicationContext(), SystemStartupService.class);
getApplicationContext().stopService(intent);
}

System.runFinalizersOnExit(true);
System.exit(0);
mMainThreadWorker.schedule(() -> {
System.runFinalizersOnExit(true);
System.exit(0);
}, 100, TimeUnit.MILLISECONDS);
}

/**
Expand Down Expand Up @@ -718,11 +721,11 @@ protected void onSaveInstanceState(Bundle outState) {
outState.putSerializable(SEEN_ANNOUNCEMENTS, this.seenAnnouncements.toArray());
}

private void showSnackbar(int infoRes){
private void showSnackbar(int infoRes) {
showSnackbar(getString(infoRes));
}

private void showSnackbar(String info){
private void showSnackbar(String info) {
mMainThreadWorker.schedule(() -> {
if (mDrawerLayout != null) {
Snackbar.make(mDrawerLayout, info, Snackbar.LENGTH_LONG).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class PreferencesHandler implements PreferenceConstants {
public static final boolean DEFAULT_BLUETOOTH_AUTOCONNECT = false;
public static final boolean DEFAULT_DISPLAY_STAYS_ACTIVE = false;
public static final boolean DEFAULT_TEXT_TO_SPEECH = false;
public static final boolean DEFAULT_BLUETOOTH_SERVICE_AUTOSTART = true;


public static boolean isAutoconnectEnabled(Context context) {
Expand All @@ -50,6 +51,17 @@ public static Observable<Boolean> getAutoconnectObservable(final Context context
.asObservable();
}

public static boolean isBackgroundHandlerEnabled(Context context){
return PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(PREF_BLUETOOTH_SERVICE_AUTOSTART, DEFAULT_BLUETOOTH_SERVICE_AUTOSTART);
}

public static Observable<Boolean> getBackgroundHandlerEnabledObservable(final Context context){
return RxSharedPreferences.create(getSharedPreferences(context))
.getBoolean(PREF_BLUETOOTH_SERVICE_AUTOSTART, DEFAULT_BLUETOOTH_SERVICE_AUTOSTART)
.asObservable();
}

public static int getDiscoveryInterval(Context context) {
return getSharedPreferences(context)
.getInt(PREF_BLUETOOTH_DISCOVERY_INTERVAL, DEFAULT_BLUETOOTH_DISCOVERY_INTERVAL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.envirocar.core.trackprocessing.CalculatedMAFWithStaticVolumetricEfficiency;
import org.envirocar.core.trackprocessing.ConsumptionAlgorithm;
import org.envirocar.core.utils.CarUtils;
import org.envirocar.core.utils.ServiceUtils;
import org.envirocar.obd.ConnectionListener;
import org.envirocar.obd.OBDController;
import org.envirocar.obd.bluetooth.BluetoothSocketWrapper;
Expand All @@ -75,12 +76,22 @@
import rx.schedulers.Schedulers;
import rx.subjects.PublishSubject;

import static org.envirocar.app.services.obd.OBDServiceHandler.context;

/**
* @author dewall
*/
public class OBDConnectionService extends BaseInjectorService {
private static final Logger LOG = Logger.getLogger(OBDConnectionService.class);

public static void startService(Context context){
ServiceUtils.startService(context, OBDConnectionService.class);
}

public static void stopService(Context context){
ServiceUtils.stopService(context, OBDConnectionService.class);
}

protected static final int MAX_RECONNECT_COUNT = 2;
public static final int BG_NOTIFICATION_ID = 42;

Expand Down Expand Up @@ -371,7 +382,7 @@ private void stopOBDConnection() {
}

mLocationHandler.stopLocating();
showServiceStateStoppedNotification();
// showServiceStateStoppedNotification();
doTextToSpeech("Device disconnected");

// Set state of the remoteService to stopped.
Expand Down Expand Up @@ -446,18 +457,18 @@ public void onNext(Measurement measurement) {
}


private void showServiceStateStoppedNotification() {
NotificationManager manager = (NotificationManager) getSystemService(Context
.NOTIFICATION_SERVICE);
Notification noti = new NotificationCompat.Builder(getApplicationContext())
.setContentTitle("enviroCar")
.setContentText(getResources()
.getText(R.string.service_state_stopped))
.setSmallIcon(R.drawable.dashboard)
.setAutoCancel(true)
.build();
manager.notify(BG_NOTIFICATION_ID, noti);
}
// private void showServiceStateStoppedNotification() {
// NotificationManager manager = (NotificationManager) getSystemService(Context
// .NOTIFICATION_SERVICE);
// Notification noti = new NotificationCompat.Builder(getApplicationContext())
// .setContentTitle("enviroCar")
// .setContentText(getResources()
// .getText(R.string.service_state_stopped))
// .setSmallIcon(R.drawable.dashboard)
// .setAutoCancel(true)
// .build();
// manager.notify(BG_NOTIFICATION_ID, noti);
// }

private final class OBDConnectionRecognizer {
private static final long OBD_INTERVAL = 1000 * 10; // 10 seconds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@
public class SystemStartupService extends Service {
private static final Logger LOGGER = Logger.getLogger(SystemStartupService.class);

public static final void startService(Context context){
ServiceUtils.startService(context, SystemStartupService.class);
}

public static final void stopService(Context context){
ServiceUtils.stopService(context, SystemStartupService.class);
}

private static final int REDISCOVERY_INTERVAL = 30;

// Static identifiers for actions for the broadcast receiver.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public static void setRecordingState(OBDServiceState state) {
.setContentTitle(context.getString(state.getTitle()))
.setPriority(Integer.MAX_VALUE)
.setContent(smallView)
.setOngoing(true)
.setAutoCancel(true)
.build();

// Check whether the notification state has content for the bigView, i.e. it provides an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ private void replaceFragment(Fragment fragment, int container, int enterAnimatio
}

transaction.replace(container, fragment);
transaction.commit();
transaction.commitAllowingStateLoss();

mCurrentlyVisible = fragment;
}
Expand Down
Loading

0 comments on commit 384ddbb

Please sign in to comment.