Skip to content
This repository has been archived by the owner on Mar 10, 2022. It is now read-only.

Commit

Permalink
Added autostart Torque and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jilleb committed Dec 21, 2018
1 parent 69d8e32 commit fc8bad4
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions app/src/main/java/com/mqbcoding/stats/DashboardFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;

public class DashboardFragment extends CarFragment {
private final String TAG = "DashboardFragment";
Expand Down Expand Up @@ -121,12 +123,13 @@ public void onClick(View v) {
public void onNewMeasurements(String provider, Date timestamp, Map<String, Object> values) {
mLastMeasurements.putAll(values);
Log.i(TAG, "onCarStatsClient.Listener");
postUpdate();
}
@Override
public void onSchemaChanged() {
// do nothing
}


};

private final ServiceConnection mServiceConnection = new ServiceConnection() {
Expand All @@ -138,6 +141,7 @@ public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
mWheelStateMonitor = carStatsBinder.getWheelStateMonitor();
mLastMeasurements = mStatsClient.getMergedMeasurements();
mStatsClient.registerListener(mCarStatsListener);
doUpdate();
}

@Override
Expand Down Expand Up @@ -195,8 +199,25 @@ public void onAttach(Context context) {
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "onCreate");
startTorque();
updateDisplay();

}

private void updateDisplay() {
Timer timer = new Timer();
timer.schedule(new TimerTask() {

@Override
public void run() {
postUpdate();
}

},0,1000);//Update text every second
}



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Expand Down Expand Up @@ -586,7 +607,6 @@ public void run() {
public void onStart() {
super.onStart();
Log.i(TAG, "onStart");
postUpdate();
}

@Override
Expand Down Expand Up @@ -1184,7 +1204,7 @@ private void setupClocks(String queryClock, Speedometer clock, TextView icon, Ra
setupClock(icon,"ic_battery","",clock,false,"G",0,100,"integer");
break;
case "torque-phonebarometer_0xff1270":
setupClock(icon,"ic_none","",clock,false,"",900,1300,"integer");
setupClock(icon,"ic_none","",clock,false,"",900,1300,"float");
break;
case "torque-obdadaptervoltage_0xff1238":
setupClock(icon,"ic_obd2","",clock,false,"G",0,17,"float");
Expand Down Expand Up @@ -1719,6 +1739,8 @@ private void startTorque ()
Intent intent = new Intent();
intent.setClassName("org.prowl.torque", "org.prowl.torque.remote.TorqueService");
getContext().startService(intent);
Log.d(TAG,"Torque start");

boolean successfulBind = getContext().bindService(intent, torqueConnection, 0);
if (successfulBind) {
torqueBind=true;
Expand Down

0 comments on commit fc8bad4

Please sign in to comment.