Skip to content

Commit

Permalink
Add icons for gps and gsm signal strength to info sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp0002 committed Oct 14, 2023
1 parent 6d52a1e commit fb5f362
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -40,7 +41,9 @@ public class DeviceInfoSheet extends BottomSheetDialogFragment implements Device
private TextView deviceSerialNumber;
private TextView deviceLastCommunication;
private TextView deviceGPSSignal;
private ImageView deviceGPSSignalIcon;
private TextView deviceGSMSignal;
private ImageView deviceGSMSignalIcon;
private TextView deviceIsStopped;
private TextView deviceSpeed;
private TextView deviceDistance;
Expand Down Expand Up @@ -93,7 +96,9 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
deviceCourseDesc = view.findViewById(R.id.deviceCourseDesc);
deviceLastCommunication = view.findViewById(R.id.deviceLastCommunication);
deviceGPSSignal = view.findViewById(R.id.deviceGPSSignal);
deviceGPSSignalIcon = view.findViewById(R.id.deviceGPSSignalIcon);
deviceGSMSignal = view.findViewById(R.id.deviceGSMSignal);
deviceGSMSignalIcon = view.findViewById(R.id.deviceGSMSignalIcon);
deviceIsStopped = view.findViewById(R.id.deviceStopped);
deviceSpeed = view.findViewById(R.id.deviceSpeed);
deviceDistance = view.findViewById(R.id.deviceDistance);
Expand All @@ -104,6 +109,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
}

private void updateView(Device device) {
int gpsSignal = Integer.parseInt(device.GPS);
int gsmSignal = Integer.parseInt(device.GSM);
deviceName.setText(device.name);
deviceStatus.setText(device.status);
deviceGroupName.setText(device.groupName);
Expand All @@ -121,8 +128,10 @@ private void updateView(Device device) {
deviceId.setText(device.id);
deviceCourseDesc.setText(device.coursedesc);
deviceLastCommunication.setText(device.lastCommunication);
deviceGPSSignal.setText(device.GPS);
deviceGSMSignal.setText(device.GSM);
deviceGPSSignal.setText(getString(Utils.getGpsHint(gpsSignal)) + " (" + device.GPS + ")");
deviceGPSSignalIcon.setImageResource(Utils.getGpsIcon(gpsSignal));
deviceGSMSignal.setText(getString(Utils.getGsmHint(gsmSignal)) + " (" + device.GSM + ")");
deviceGSMSignalIcon.setImageResource(Utils.getGsmIcon(gsmSignal));
deviceIsStopped.setText("1".equals(device.isStop) ? R.string.yes : R.string.no);
deviceSpeed.setText(device.speed + " km/h");
deviceDistance.setText(device.distance);
Expand Down
41 changes: 41 additions & 0 deletions app/src/main/java/de/raffaelhahn/xadgps_client/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package de.raffaelhahn.xadgps_client;

public class Utils {

public static int getGpsIcon(int gpsSignal) {
return gpsSignal >= 5 ? R.drawable.satellite_strong : R.drawable.satellite_weak;
}

public static int getGsmIcon(int gsmSignal) {
if(gsmSignal >= 24) {
return R.drawable.signal4;
} else if(gsmSignal >= 21) {
return R.drawable.signal3;
} else if(gsmSignal >= 18) {
return R.drawable.signal2;
} else if(gsmSignal >= 15) {
return R.drawable.signal1;
} else {
return R.drawable.signal0;
}
}

public static int getGpsHint(int gpsSignal) {
if (gpsSignal >= 5) {
return R.string.signal_strength_strong;
} else {
return R.string.signal_strength_weak;
}
}

public static int getGsmHint(int gsmSignal) {
if (gsmSignal >= 21) {
return R.string.signal_strength_strong;
} else if (gsmSignal >= 15) {
return R.string.signal_strength_normal;
} else {
return R.string.signal_strength_weak;
}
}

}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/satellite_strong.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M15.44,0.59l-3.18,3.18c-0.78,0.78 -0.78,2.05 0,2.83l1.24,1.24l-0.71,0.71L11.55,7.3c-0.78,-0.78 -2.05,-0.78 -2.83,0L7.3,8.72c-0.78,0.78 -0.78,2.05 0,2.83l1.24,1.24l-0.71,0.71L6.6,12.25c-0.78,-0.78 -2.05,-0.78 -2.83,0l-3.18,3.18c-0.78,0.78 -0.78,2.05 0,2.83l3.54,3.54c0.78,0.78 2.05,0.78 2.83,0l3.18,-3.18c0.78,-0.78 0.78,-2.05 0,-2.83l-1.24,-1.24l0.71,-0.71l1.24,1.24c0.78,0.78 2.05,0.78 2.83,0l1.41,-1.41c0.78,-0.78 0.78,-2.05 0,-2.83L13.84,9.6l0.71,-0.71l1.24,1.24c0.78,0.78 2.05,0.78 2.83,0l3.18,-3.18c0.78,-0.78 0.78,-2.05 0,-2.83l-3.54,-3.54C17.48,-0.2 16.22,-0.2 15.44,0.59zM6.6,19.32l-1.06,1.06L2,16.85l1.06,-1.06L6.6,19.32zM8.72,17.2l-1.06,1.06l-3.54,-3.54l1.06,-1.06L8.72,17.2zM18.26,7.66L17.2,8.72l-3.54,-3.54l1.06,-1.06L18.26,7.66zM20.38,5.54L19.32,6.6l-3.54,-3.54L16.85,2L20.38,5.54zM14,21l0,2c4.97,0 9,-4.03 9,-9l-2,0C21,17.87 17.87,21 14,21zM14,17l0,2c2.76,0 5,-2.24 5,-5l-2,0C17,15.66 15.66,17 14,17z"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/satellite_weak.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="960dp"
android:height="960dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="#FF000000"
android:pathData="M774,272L816,230L674,88L632,130L774,272ZM689,357L731,315L589,173L547,215L689,357ZM307,739L349,697L207,555L165,597L307,739ZM222,824L264,782L122,640L80,682L222,824ZM222,903C212,903 202,901 192,897C182,893 173,887.33 165,880L23,738C15.67,730 10,721 6,711C2,701 0,691 0,681C0,670.33 2,660.17 6,650.5C10,640.83 15.67,632.33 23,625L150,498C165.33,482.67 184.33,474.83 207,474.5C229.67,474.17 248.67,481.67 264,497L314,547L342,519L292,469C276.67,453.67 269,435 269,413C269,391 276.67,372.33 292,357L349,300C364.33,284.67 383.17,277 405.5,277C427.83,277 446.67,284.67 462,300L512,350L540,322L490,272C474.67,256.67 467,237.83 467,215.5C467,193.17 474.67,174.33 490,159L617,32C625,24 634,18 644,14C654,10 664,8 674,8C684,8 693.83,10 703.5,14C713.17,18 722,24 730,32L872,174C880,181.33 885.83,189.83 889.5,199.5C893.17,209.17 895,219.33 895,230C895,240 893.17,250 889.5,260C885.83,270 880,279 872,287L745,414C729.67,429.33 710.83,437 688.5,437C666.17,437 647.33,429.33 632,414L582,364L554,392L604,442C619.33,457.33 626.83,476.17 626.5,498.5C626.17,520.83 618.33,539.67 603,555L547,611C531.67,626.33 512.83,634 490.5,634C468.17,634 449.33,626.33 434,611L384,561L356,589L406,639C421.33,654.33 428.83,673.33 428.5,696C428.17,718.67 420.33,737.67 405,753L278,880C270.67,887.33 262.17,893 252.5,897C242.83,901 232.67,903 222,903ZM560,768L560,688C593.33,688 621.67,676.33 645,653C668.33,629.67 680,601.33 680,568L760,568C760,623.33 740.5,670.5 701.5,709.5C662.5,748.5 615.33,768 560,768Z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/signal0.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M80,880L880,80L880,880L80,880ZM273,800L800,800L800,274L273,800Z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/signal1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M80,880L880,80L880,880L80,880ZM400,800L800,800L800,274L400,674L400,800Z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/signal2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M80,880L880,80L880,880L80,880ZM520,800L800,800L800,274L520,554L520,800Z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/signal3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M80,880L880,80L880,880L80,880ZM600,800L800,800L800,274L600,474L600,800Z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/signal4.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M80,880L880,80L880,880L80,880Z"/>
</vector>
57 changes: 47 additions & 10 deletions app/src/main/res/layout/device_info_sheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,22 +241,59 @@
<TextView
android:text="@string/device_gps_signal"
android:padding="3dip" />
<TextView
android:id="@+id/deviceGPSSignal"
android:text="Undefined"
android:gravity="right"
android:padding="3dip" />

<androidx.constraintlayout.widget.ConstraintLayout android:gravity="right">

<ImageView
android:layout_margin="3dp"
android:id="@+id/deviceGPSSignalIcon"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
app:tint="?attr/colorOnBackground"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>

<TextView
android:id="@+id/deviceGPSSignal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="right"
android:padding="3dip"
android:text="Undefined"
app:layout_constraintEnd_toStartOf="@id/deviceGPSSignalIcon" />
</androidx.constraintlayout.widget.ConstraintLayout>
</TableRow>

<TableRow>
<TextView
android:text="@string/device_gsm_signal"
android:padding="3dip" />
<TextView
android:id="@+id/deviceGSMSignal"
android:text="Undefined"
android:gravity="right"
android:padding="3dip" />

<androidx.constraintlayout.widget.ConstraintLayout
android:gravity="right">

<ImageView
android:layout_margin="3dp"
android:id="@+id/deviceGSMSignalIcon"
android:layout_height="0dp"
android:layout_width="0dp"
app:tint="?attr/colorOnBackground"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />

<TextView
android:id="@+id/deviceGSMSignal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="right"
android:padding="3dip"
android:text="Undefined"
app:layout_constraintEnd_toStartOf="@id/deviceGSMSignalIcon" />
</androidx.constraintlayout.widget.ConstraintLayout>
</TableRow>

<TableRow>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<string name="device_parked">Geparkt</string>
<string name="device_moving">Fährt</string>

<string name="signal_strength_strong">Stark</string>
<string name="signal_strength_normal">Normal</string>
<string name="signal_strength_weak">Schwach</string>

<string name="action_show_on_map">Auf Karte anzeigen</string>

<string name="tracking_loading_header">Tracking lädt...</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<string name="device_gsm_signal">GSM Signal</string>
<string name="device_parked">Parked</string>
<string name="device_moving">Moving</string>

<string name="signal_strength_strong">Strong</string>
<string name="signal_strength_normal">Normal</string>
<string name="signal_strength_weak">Poor</string>

<string name="action_show_on_map">Show on map</string>

Expand Down

0 comments on commit fb5f362

Please sign in to comment.