[android] add support for schuko/type-E charge sockets

The commit is slightly more complicated that expected because:

- it adds supports for both schuko and type-E, using the same icon (but
  maintaining the underlying type annotated in OSM)

- it adds logic to *not* display the power of schuko socket as 'unknown'
  when not provided in OSM, as it is 'implicit' (3.7kW in most
  countries)

Signed-off-by: Séverin Lemaignan <severin@guakamole.org>
This commit is contained in:
Séverin Lemaignan
2025-11-25 22:44:34 +01:00
committed by x7z4w
parent 610737d295
commit 6d0111b434
8 changed files with 108 additions and 18 deletions

View File

@@ -1,5 +1,7 @@
package app.organicmaps.editor;
import static android.view.View.INVISIBLE;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
@@ -396,16 +398,18 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
typeBtns.removeAllViews();
List<String> SOCKET_TYPES = Arrays.stream(getResources().getStringArray(R.array.charge_socket_types)).toList();
for (String socket : SOCKET_TYPES)
for (String socketType : SOCKET_TYPES)
{
ChargeSocketDescriptor socket = new ChargeSocketDescriptor(socketType,0,0);
MaterialButton btn = (MaterialButton) inflater.inflate(R.layout.button_socket_type, typeBtns, false);
btn.setTag(R.id.socket_type, socket);
btn.setTag(R.id.socket_type, socket.type());
// load SVG icon converted into VectorDrawable in res/drawable
@SuppressLint("DiscouragedApi")
int resIconId =
getResources().getIdentifier("ic_charge_socket_" + socket, "drawable", requireContext().getPackageName());
getResources().getIdentifier("ic_charge_socket_" + socket.visualType(), "drawable", requireContext().getPackageName());
if (resIconId != 0)
{
btn.setIcon(getResources().getDrawable(resIconId));
@@ -413,7 +417,7 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
@SuppressLint("DiscouragedApi")
int resTypeId =
getResources().getIdentifier("charge_socket_" + socket, "string", requireContext().getPackageName());
getResources().getIdentifier("charge_socket_" + socket.visualType(), "string", requireContext().getPackageName());
if (resTypeId != 0)
{
btn.setText(getResources().getString(resTypeId));
@@ -601,8 +605,7 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
GridLayout socketsGrid = mChargeSockets.findViewById(R.id.socket_grid_editor);
socketsGrid.removeAllViews();
for (int i = 0; i < sockets.length; i++)
{
for (int i = 0; i < sockets.length; i++) {
final int currentIndex = i;
ChargeSocketDescriptor socket = sockets[i];
@@ -613,28 +616,29 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
MaterialTextView power = itemView.findViewById(R.id.socket_power);
MaterialTextView count = itemView.findViewById(R.id.socket_count);
// load SVG icon converted into VectorDrawable in res/drawable
@SuppressLint("DiscouragedApi")
int resIconId = getResources().getIdentifier("ic_charge_socket_" + socket.type(), "drawable",
requireContext().getPackageName());
if (resIconId != 0)
{
int resIconId = getResources().getIdentifier("ic_charge_socket_" + socket.visualType(), "drawable",
requireContext().getPackageName());
if (resIconId != 0) {
icon.setImageResource(resIconId);
}
@SuppressLint("DiscouragedApi")
int resTypeId =
getResources().getIdentifier("charge_socket_" + socket.type(), "string", requireContext().getPackageName());
if (resTypeId != 0)
{
getResources().getIdentifier("charge_socket_" + socket.visualType(), "string", requireContext().getPackageName());
if (resTypeId != 0) {
type.setText(resTypeId);
}
if (socket.power() != 0)
{
if (socket.power() != 0) {
DecimalFormat df = new DecimalFormat("#.##");
power.setText(getString(R.string.kw_label, df.format(socket.power())));
}
else if (socket.ignorePower()) {
power.setVisibility(INVISIBLE);
}
if (socket.count() != 0)
{

View File

@@ -1,5 +1,7 @@
package app.organicmaps.widget.placepage.sections;
import static android.view.View.INVISIBLE;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -89,7 +91,7 @@ public class PlacePageChargeSocketsFragment extends Fragment implements Observer
// load SVG icon converted into VectorDrawable in res/drawable
@SuppressLint("DiscouragedApi")
int resIconId = getResources().getIdentifier("ic_charge_socket_" + socket.type(), "drawable",
int resIconId = getResources().getIdentifier("ic_charge_socket_" + socket.visualType(), "drawable",
requireContext().getPackageName());
if (resIconId != 0)
{
@@ -98,7 +100,7 @@ public class PlacePageChargeSocketsFragment extends Fragment implements Observer
@SuppressLint("DiscouragedApi")
int resTypeId =
getResources().getIdentifier("charge_socket_" + socket.type(), "string", requireContext().getPackageName());
getResources().getIdentifier("charge_socket_" + socket.visualType(), "string", requireContext().getPackageName());
if (resTypeId != 0)
{
type.setText(resTypeId);
@@ -109,6 +111,9 @@ public class PlacePageChargeSocketsFragment extends Fragment implements Observer
DecimalFormat df = new DecimalFormat("#.##");
power.setText(getString(R.string.kw_label, df.format(socket.power())));
}
else if (socket.ignorePower()) {
power.setVisibility(INVISIBLE);
}
if (socket.count() != 0)
{

View File

@@ -887,6 +887,7 @@
<string name="charge_socket_power">Potencia (kW)</string>
<string name="unknown_count">desconocido</string>
<string name="avoid_steps">Evitar escaleras</string>
<string name="charge_socket_schuko">Doméstico UE</string>
<string name="unknown_socket_type">enchufe desconocido</string>
<string name="edit_socket_info_tooltip">Crear nuevo enchufe o editar existentes.</string>
<string name="charging_station_available_sockets">Enchufes disponibles</string>

View File

@@ -30,6 +30,7 @@
<item>type1</item>
<item>type2_cable</item>
<item>type2</item>
<item>schuko</item>
<item>unknown</item>
</string-array>

View File

@@ -939,6 +939,7 @@
<string name="charge_socket_type1">Type 1</string>
<string name="charge_socket_nacs">NACS</string>
<string name="charge_socket_chademo">CHAdeMO</string>
<string name="charge_socket_schuko">Domestic EU</string>
<string name="unknown_socket_type">unknown socket</string>
<string name="edit_socket_info_tooltip">Create new sockets or edit existing ones.</string>
<string name="charging_station_available_sockets">Available sockets</string>