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

Commit 7b118e5

Browse files
committed
added Location data source (Geocoding, Google maps)
Minor fix
1 parent 10d76e1 commit 7b118e5

File tree

7 files changed

+116
-43
lines changed

7 files changed

+116
-43
lines changed

app/src/main/java/com/mqbcoding/stats/DashboardFragment.java

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import android.graphics.PorterDuff;
1717
import android.graphics.Typeface;
1818
import android.graphics.drawable.Drawable;
19+
import android.location.Address;
1920
import android.os.Bundle;
2021
import android.os.Handler;
2122
import android.os.IBinder;
@@ -88,6 +89,7 @@ public class DashboardFragment extends CarFragment {
8889
private TextView mValueElement1, mValueElement2, mValueElement3, mValueElement4, mTitleElement,
8990
mTitleElementRight, mTitleElementLeft, mTitleElementNavDistance, mTitleElementNavTime, mTitleNAVDestinationAddress;
9091
private TextView mTitleIcon1, mTitleIcon2, mTitleIcon3, mTitleIcon4, mTitleClockLeft, mTitleClockCenter, mTitleClockRight;
92+
private TextView mTitleConsumptionLeft, mTitleConsumptionCenter, mTitleConsumptionRight;
9193
private ConstraintLayout mConstraintClockLeft, mConstraintClockRight, mConstraintClockCenter;
9294
private ConstraintLayout mConstraintGraphLeft, mConstraintGraphRight, mConstraintGraphCenter;
9395
private ConstraintLayout mConstraintElementLeft, mConstraintElementRight, mConstraintElementCenter;
@@ -141,6 +143,7 @@ public class DashboardFragment extends CarFragment {
141143
private static final String FORMAT_VOLT0 = "-,-V";
142144
private boolean celsiusTempUnit;
143145
private boolean showStreetName, useGoogleGeocoding, forceGoogleGeocoding;
146+
private String sourceLocation;
144147
private String selectedFont;
145148
private boolean selectedPressureUnits;
146149
private int updateSpeed = 2000;
@@ -406,7 +409,9 @@ private void setupViews(View rootView) {
406409
mTitleClockLeft = rootView.findViewById(R.id.textTitleLabel1);
407410
mTitleClockCenter = rootView.findViewById(R.id.textTitleLabel2);
408411
mTitleClockRight = rootView.findViewById(R.id.textTitleLabel3);
409-
412+
mTitleConsumptionLeft = rootView.findViewById(R.id.textTitleConsumptionLeft);
413+
mTitleConsumptionCenter = rootView.findViewById(R.id.textTitleConsumptionCenter);
414+
mTitleConsumptionRight = rootView.findViewById(R.id.textTitleConsumptionRight);
410415
mTitleElementNavDistance = rootView.findViewById(R.id.textTitleNavDistance);
411416
mTitleElementNavTime = rootView.findViewById(R.id.textTitleNavTime);
412417

@@ -523,16 +528,16 @@ private void setupTypeface(String selectedFont) {
523528
mTitleClockLeft.setTypeface(typeface);
524529
mTitleClockCenter.setTypeface(typeface);
525530
mTitleClockRight.setTypeface(typeface);
531+
mTitleConsumptionLeft.setTypeface(typeface);
532+
mTitleConsumptionCenter.setTypeface(typeface);
533+
mTitleConsumptionRight.setTypeface(typeface);
526534
mTitleElementNavDistance.setTypeface(typeface);
527535
mTitleElementNavTime.setTypeface(typeface);
528536
mtextTitleMain.setTypeface(typeface);
529537

530538
//max
531-
//mTextMinLeft.setTypeface(typeface);
532539
mTextMaxLeft.setTypeface(typeface);
533-
//mTextMinCenter.setTypeface(typeface);
534540
mTextMaxCenter.setTypeface(typeface);
535-
//mTextMinRight.setTypeface(typeface);
536541
mTextMaxRight.setTypeface(typeface);
537542

538543
Log.d(TAG, "font: " + typeface);
@@ -554,6 +559,7 @@ private void onPreferencesChangeHandler() {
554559
mBtnNext.setVisibility(View.VISIBLE);
555560
mBtnPrev.setVisibility(View.VISIBLE);
556561
mtextTitleMain.setVisibility(View.VISIBLE);
562+
mtextTitleMain.setTextColor(Color.WHITE);
557563
}
558564

559565
// Load this only on first run, then leave it alone
@@ -563,6 +569,7 @@ private void onPreferencesChangeHandler() {
563569
showStreetName = sharedPreferences.getBoolean("showStreetNameInTitle", true);
564570
useGoogleGeocoding = sharedPreferences.getBoolean("useGoogleGeocoding", false);
565571
forceGoogleGeocoding = sharedPreferences.getBoolean("forceGoogleGeocoding", false);
572+
sourceLocation = sharedPreferences.getString("locationSourceData","Geocoding");
566573
fueltanksize = Float.parseFloat(sharedPreferences.getString("fueltanksize", "50"));
567574

568575
float speedLeft = MaxspeedLeft[dashboardNum];
@@ -578,7 +585,12 @@ private void onPreferencesChangeHandler() {
578585
mTextMaxRight.setText(String.format(Locale.US, FORMAT_DECIMALS, speedRight));
579586

580587
String dashboardId = String.valueOf(dashboardNum);
581-
String mtextTitlePerformance = sharedPreferences.getString("performanceTitle" + dashboardId, "Performance monitor" + dashboardId);
588+
String mtextTitlePerformance;
589+
if (dashboardNum<4) {
590+
mtextTitlePerformance = sharedPreferences.getString("performanceTitle" + dashboardId, "Performance monitor" + dashboardId);
591+
} else {
592+
mtextTitlePerformance = getResources().getString(R.string.pref_title_performance_4);
593+
}
582594

583595
mtextTitleMain.setText(mtextTitlePerformance);
584596

@@ -957,14 +969,14 @@ public void onResume() {
957969
getContext().bindService(serviceIntent, mVexServiceConnection, Context.BIND_AUTO_CREATE);
958970
startTorque();
959971
createAndStartUpdateTimer();
960-
/* if (useGoogleGeocoding) {
972+
if (useGoogleGeocoding) {
961973
if(!getContext().bindService(new Intent(getContext(), GeocodeLocationService.class),
962974
mGeocodingServiceConnection,
963975
Context.BIND_AUTO_CREATE)) {
964976
Log.e("Geocode", "Cannot bind?!");
965977
}
966978
}
967-
*/
979+
968980
LocalBroadcastManager.getInstance(getContext())
969981
.registerReceiver(onNoticeGoogleNavigationUpdate, new IntentFilter("GoogleNavigationUpdate"));
970982
LocalBroadcastManager.getInstance(getContext())
@@ -982,7 +994,7 @@ public void onResume() {
982994
//Dashboard5_On = sharedPreferences.getBoolean("d5_active", false); //Enabled dasboard5
983995
Dashboard5_On = false;
984996
}
985-
/*
997+
986998
private final GeocodeLocationService.IGeocodeResult geocodeResultListener = new GeocodeLocationService.IGeocodeResult() {
987999
@Override
9881000
public void onNewGeocodeResult(Address result) {
@@ -999,25 +1011,29 @@ public void onNewGeocodeResult(Address result) {
9991011
// tmp = result.getPostalCode(); //PostalCode
10001012
// if (tmp != null)
10011013
// sb.append("("+tmp+")");
1014+
tmp = result.getUrl(); //URL -> Altitude
1015+
if (tmp != null)
1016+
sb.append("("+tmp+")");
1017+
10021018
googleGeocodeLocationStr = sb.toString();
10031019
}
10041020
};
10051021

10061022
private final ServiceConnection mGeocodingServiceConnection = new ServiceConnection() {
10071023
@Override
10081024
public void onServiceConnected(ComponentName name, IBinder service) {
1009-
// mGeocodingService = ((GeocodeLocationService.LocalBinder)service).getService();
1010-
// mGeocodingService.setOnNewGeocodeListener(geocodeResultListener);
1025+
mGeocodingService = ((GeocodeLocationService.LocalBinder)service).getService();
1026+
mGeocodingService.setOnNewGeocodeListener(geocodeResultListener);
10111027
Log.d("Geocode", "Service connected");
10121028
}
10131029

10141030
@Override
10151031
public void onServiceDisconnected(ComponentName name) {
10161032
Log.e("Geocode", "Service disconnected");
1017-
// mGeocodingService = null;
1033+
mGeocodingService = null;
10181034
}
10191035
};
1020-
*/
1036+
10211037
private void startTorque() {
10221038
Intent intent = new Intent();
10231039
intent.setClassName("org.prowl.torque", "org.prowl.torque.remote.TorqueService");
@@ -1069,7 +1085,7 @@ public void onPause() {
10691085
mStatsClient.unregisterListener(mCarStatsListener);
10701086
getContext().unbindService(mVexServiceConnection);
10711087
if (useGoogleGeocoding) {
1072-
// getContext().unbindService(mGeocodingServiceConnection);
1088+
getContext().unbindService(mGeocodingServiceConnection);
10731089
}
10741090

10751091
if (torqueBind)
@@ -1115,6 +1131,9 @@ public void onDestroyView() {
11151131
mTitleClockLeft = null;
11161132
mTitleClockCenter = null;
11171133
mTitleClockRight = null;
1134+
mTitleConsumptionLeft = null;
1135+
mTitleConsumptionCenter = null;
1136+
mTitleConsumptionRight = null;
11181137
mTitleElementNavDistance = null;
11191138
mTitleElementNavTime = null;
11201139
mTitleIcon1 = null;
@@ -1212,7 +1231,7 @@ private void SetLayoutElements(TextView mValueElement, String mMeasurements, Str
12121231
if (mGetMeasurement==null) mGetMeasurement= Float.valueOf(0);
12131232
mGetMeasurement = mGetMeasurement * fueltanksize;
12141233
Float mShortCons = (Float) mLastMeasurements.get("shortTermConsumptionPrimary");
1215-
Float mLongCons = (Float) mLastMeasurements.get("shortTermConsumptionPrimary");
1234+
Float mLongCons = (Float) mLastMeasurements.get("LongTermConsumptionPrimary");
12161235
if (mShortCons==null || mShortCons==0){
12171236
if (mLongCons==null || mLongCons==0){
12181237
mGetMeasurement = Float.valueOf(0);
@@ -1364,7 +1383,6 @@ private void doUpdate() {
13641383
mConstraintClockCenter.setVisibility(View.INVISIBLE);
13651384
mConstraintClockRight.setVisibility(View.INVISIBLE);
13661385

1367-
//TODO: Refresh elements
13681386
UpdateLayoutElements();
13691387
}
13701388

@@ -2363,21 +2381,34 @@ private void updateTitle() {
23632381
mTitleClockRight.setText(mLabelClockR);
23642382
mBtnNext.setVisibility(View.VISIBLE);
23652383
mBtnPrev.setVisibility(View.VISIBLE);
2366-
mtextTitleMain.setVisibility(View.VISIBLE);
2384+
//mtextTitleMain.setVisibility(View.VISIBLE);
2385+
mtextTitleMain.setTextColor(Color.WHITE);
2386+
mTitleConsumptionRight.setVisibility(View.VISIBLE);
2387+
mTitleConsumptionLeft.setVisibility(View.VISIBLE);
2388+
mTitleConsumptionCenter.setVisibility(View.VISIBLE);
23672389
} else if (!proximityOn) {
23682390
mTitleClockLeft.setText("");
23692391
mTitleClockCenter.setText("");
23702392
mTitleClockRight.setText("");
23712393
mBtnNext.setVisibility(View.VISIBLE);
23722394
mBtnPrev.setVisibility(View.VISIBLE);
2373-
mtextTitleMain.setVisibility(View.VISIBLE);
2395+
//mtextTitleMain.setVisibility(View.VISIBLE);
2396+
mtextTitleMain.setTextColor(Color.WHITE);
2397+
mTitleConsumptionRight.setVisibility(View.INVISIBLE);
2398+
mTitleConsumptionLeft.setVisibility(View.INVISIBLE);
2399+
mTitleConsumptionCenter.setVisibility(View.INVISIBLE);
23742400
} else {
23752401
mTitleClockLeft.setText("");
23762402
mTitleClockCenter.setText("");
23772403
mTitleClockRight.setText("");
23782404
mBtnNext.setVisibility(View.INVISIBLE);
23792405
mBtnPrev.setVisibility(View.INVISIBLE);
2380-
mtextTitleMain.setVisibility(View.INVISIBLE);
2406+
//mtextTitleMain.setVisibility(View.VISIBLE);
2407+
mtextTitleMain.setTextColor(Color.DKGRAY);
2408+
mTitleConsumptionRight.setVisibility(View.INVISIBLE);
2409+
mTitleConsumptionLeft.setVisibility(View.INVISIBLE);
2410+
mTitleConsumptionCenter.setVisibility(View.INVISIBLE);
2411+
23812412
}
23822413

23832414
String currentTime = getTime();
@@ -2389,8 +2420,13 @@ private void updateTitle() {
23892420
// Display location in left side of Title bar
23902421
if (showStreetName) {
23912422
String leftTitle="";
2392-
if (googleMapsLocationStr != null && !googleMapsLocationStr.isEmpty()) { // Google maps has always priority for now
2393-
leftTitle = googleMapsLocationStr;
2423+
Log.v(TAG,"SourceLocation: "+sourceLocation+"!!!");
2424+
if (sourceLocation.equals("Geocoding")) {
2425+
leftTitle = googleGeocodeLocationStr;
2426+
} else {
2427+
if (googleMapsLocationStr != null && !googleMapsLocationStr.isEmpty()) {
2428+
leftTitle = googleMapsLocationStr;
2429+
}
23942430
}
23952431
if (!forceGoogleGeocoding) {
23962432
String location1 = (String) mLastMeasurements.get("Nav_CurrentPosition.Street");
@@ -2644,6 +2680,11 @@ private void updateElement(String queryElement, TextView value, TextView label)
26442680
Float mTemperature = (Float) mLastMeasurements.get(queryElement);
26452681
if (mTemperature != null && mTemperature > 0) {
26462682
value.setText(String.format(Locale.US, FORMAT_DEGREES, mTemperature));
2683+
if (mTemperature < 70) {
2684+
value.setTextColor(Color.RED);
2685+
} else {
2686+
value.setTextColor(Color.WHITE);
2687+
}
26472688
}
26482689
break;
26492690
case "outsideTemperature":

app/src/main/java/com/mqbcoding/stats/GeocodeLocationService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,12 @@ private void initializeTimerTask() {
103103
@Override
104104
public void run() {
105105
Location lastLocation = null;
106+
int lastAltitude = 0;
106107
try {
107108
lastLocation = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
109+
lastAltitude = (int) mLastDecodedLocation.getAltitude();
108110
Log.d(TAG,"Received location: " + lastLocation);
111+
Log.d(TAG,"Received Altitude: " + lastAltitude);
109112
} catch (SecurityException ex) {
110113
Log.e(TAG, "Security Exception while getting last known location?");
111114
}
@@ -115,6 +118,7 @@ public void run() {
115118
List<Address> addresses = geocoder.getFromLocation(
116119
lastLocation.getLatitude(), lastLocation.getLongitude(), 1);
117120
if (mListener != null && addresses != null && addresses.size() > 0) {
121+
addresses.set(0,addresses.get(0)).setUrl(String.valueOf(lastAltitude)+" m");
118122
mListener.onNewGeocodeResult(addresses.get(0));
119123
mLastDecodedLocation.set(lastLocation);
120124
Log.d(TAG, "Sended location to client: " + mLastDecodedLocation);

app/src/main/res/layout/layout_dashboard_consumption.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434
app:layout_constraintBottom_toBottomOf="parent"
3535
app:layout_constraintLeft_toLeftOf="parent"
3636
app:layout_constraintRight_toRightOf="parent"
37-
app:layout_constraintTop_toBottomOf="@+id/textTitleLabelRight"
37+
app:layout_constraintTop_toBottomOf="@+id/textTitleConsumptionRight"
3838
/>
3939

4040
<TextView
41-
android:id="@+id/textTitleLabelRight"
41+
android:id="@+id/textTitleConsumptionRight"
4242
android:layout_width="275dp"
4343
android:layout_height="32dp"
4444
android:ellipsize="marquee"
@@ -63,7 +63,7 @@
6363
android:textColor="@android:color/white"
6464
android:textSize="14sp"
6565
app:layout_constraintStart_toStartOf="parent"
66-
app:layout_constraintTop_toBottomOf="@+id/textTitleLabelRight" />
66+
app:layout_constraintTop_toBottomOf="@+id/textTitleConsumptionRight" />
6767

6868
<TextView
6969
android:id="@+id/valueRightElement1"
@@ -216,11 +216,11 @@
216216
app:layout_constraintBottom_toBottomOf="parent"
217217
app:layout_constraintLeft_toLeftOf="parent"
218218
app:layout_constraintRight_toRightOf="parent"
219-
app:layout_constraintTop_toBottomOf="@+id/textTitleLabelCenter"
219+
app:layout_constraintTop_toBottomOf="@+id/textTitleConsumptionCenter"
220220
/>
221221

222222
<TextView
223-
android:id="@+id/textTitleLabelCenter"
223+
android:id="@+id/textTitleConsumptionCenter"
224224
android:layout_width="275dp"
225225
android:layout_height="32dp"
226226
android:ellipsize="marquee"
@@ -246,7 +246,7 @@
246246
android:textColor="@android:color/white"
247247
android:textSize="14sp"
248248
app:layout_constraintStart_toStartOf="parent"
249-
app:layout_constraintTop_toBottomOf="@id/textTitleLabelCenter" />
249+
app:layout_constraintTop_toBottomOf="@id/textTitleConsumptionCenter" />
250250

251251
<TextView
252252
android:id="@+id/valueCenterElement1"
@@ -400,11 +400,11 @@
400400
app:layout_constraintBottom_toBottomOf="parent"
401401
app:layout_constraintLeft_toLeftOf="parent"
402402
app:layout_constraintRight_toRightOf="parent"
403-
app:layout_constraintTop_toBottomOf="@+id/textTitleLabelLeft"
403+
app:layout_constraintTop_toBottomOf="@+id/textTitleConsumptionLeft"
404404
/>
405405

406406
<TextView
407-
android:id="@+id/textTitleLabelLeft"
407+
android:id="@+id/textTitleConsumptionLeft"
408408
android:layout_width="275dp"
409409
android:layout_height="32dp"
410410
android:ellipsize="marquee"
@@ -431,7 +431,7 @@
431431
android:textColor="@android:color/white"
432432
android:textSize="14sp"
433433
app:layout_constraintStart_toStartOf="parent"
434-
app:layout_constraintTop_toBottomOf="@id/textTitleLabelLeft"
434+
app:layout_constraintTop_toBottomOf="@id/textTitleConsumptionLeft"
435435
tools:ignore="HardcodedText" />
436436

437437
<TextView

0 commit comments

Comments
 (0)