mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 04:53:36 +00:00
[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:
@@ -1,5 +1,7 @@
|
|||||||
package app.organicmaps.editor;
|
package app.organicmaps.editor;
|
||||||
|
|
||||||
|
import static android.view.View.INVISIBLE;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -396,16 +398,18 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
|
|||||||
typeBtns.removeAllViews();
|
typeBtns.removeAllViews();
|
||||||
|
|
||||||
List<String> SOCKET_TYPES = Arrays.stream(getResources().getStringArray(R.array.charge_socket_types)).toList();
|
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);
|
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
|
// load SVG icon converted into VectorDrawable in res/drawable
|
||||||
@SuppressLint("DiscouragedApi")
|
@SuppressLint("DiscouragedApi")
|
||||||
int resIconId =
|
int resIconId =
|
||||||
getResources().getIdentifier("ic_charge_socket_" + socket, "drawable", requireContext().getPackageName());
|
getResources().getIdentifier("ic_charge_socket_" + socket.visualType(), "drawable", requireContext().getPackageName());
|
||||||
if (resIconId != 0)
|
if (resIconId != 0)
|
||||||
{
|
{
|
||||||
btn.setIcon(getResources().getDrawable(resIconId));
|
btn.setIcon(getResources().getDrawable(resIconId));
|
||||||
@@ -413,7 +417,7 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
|
|||||||
|
|
||||||
@SuppressLint("DiscouragedApi")
|
@SuppressLint("DiscouragedApi")
|
||||||
int resTypeId =
|
int resTypeId =
|
||||||
getResources().getIdentifier("charge_socket_" + socket, "string", requireContext().getPackageName());
|
getResources().getIdentifier("charge_socket_" + socket.visualType(), "string", requireContext().getPackageName());
|
||||||
if (resTypeId != 0)
|
if (resTypeId != 0)
|
||||||
{
|
{
|
||||||
btn.setText(getResources().getString(resTypeId));
|
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);
|
GridLayout socketsGrid = mChargeSockets.findViewById(R.id.socket_grid_editor);
|
||||||
socketsGrid.removeAllViews();
|
socketsGrid.removeAllViews();
|
||||||
|
|
||||||
for (int i = 0; i < sockets.length; i++)
|
for (int i = 0; i < sockets.length; i++) {
|
||||||
{
|
|
||||||
final int currentIndex = i;
|
final int currentIndex = i;
|
||||||
ChargeSocketDescriptor socket = sockets[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 power = itemView.findViewById(R.id.socket_power);
|
||||||
MaterialTextView count = itemView.findViewById(R.id.socket_count);
|
MaterialTextView count = itemView.findViewById(R.id.socket_count);
|
||||||
|
|
||||||
|
|
||||||
// load SVG icon converted into VectorDrawable in res/drawable
|
// load SVG icon converted into VectorDrawable in res/drawable
|
||||||
@SuppressLint("DiscouragedApi")
|
@SuppressLint("DiscouragedApi")
|
||||||
int resIconId = getResources().getIdentifier("ic_charge_socket_" + socket.type(), "drawable",
|
int resIconId = getResources().getIdentifier("ic_charge_socket_" + socket.visualType(), "drawable",
|
||||||
requireContext().getPackageName());
|
requireContext().getPackageName());
|
||||||
if (resIconId != 0)
|
if (resIconId != 0) {
|
||||||
{
|
|
||||||
icon.setImageResource(resIconId);
|
icon.setImageResource(resIconId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("DiscouragedApi")
|
@SuppressLint("DiscouragedApi")
|
||||||
int resTypeId =
|
int resTypeId =
|
||||||
getResources().getIdentifier("charge_socket_" + socket.type(), "string", requireContext().getPackageName());
|
getResources().getIdentifier("charge_socket_" + socket.visualType(), "string", requireContext().getPackageName());
|
||||||
if (resTypeId != 0)
|
if (resTypeId != 0) {
|
||||||
{
|
|
||||||
type.setText(resTypeId);
|
type.setText(resTypeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (socket.power() != 0)
|
if (socket.power() != 0) {
|
||||||
{
|
|
||||||
DecimalFormat df = new DecimalFormat("#.##");
|
DecimalFormat df = new DecimalFormat("#.##");
|
||||||
power.setText(getString(R.string.kw_label, df.format(socket.power())));
|
power.setText(getString(R.string.kw_label, df.format(socket.power())));
|
||||||
}
|
}
|
||||||
|
else if (socket.ignorePower()) {
|
||||||
|
power.setVisibility(INVISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
if (socket.count() != 0)
|
if (socket.count() != 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package app.organicmaps.widget.placepage.sections;
|
package app.organicmaps.widget.placepage.sections;
|
||||||
|
|
||||||
|
import static android.view.View.INVISIBLE;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -89,7 +91,7 @@ public class PlacePageChargeSocketsFragment extends Fragment implements Observer
|
|||||||
|
|
||||||
// load SVG icon converted into VectorDrawable in res/drawable
|
// load SVG icon converted into VectorDrawable in res/drawable
|
||||||
@SuppressLint("DiscouragedApi")
|
@SuppressLint("DiscouragedApi")
|
||||||
int resIconId = getResources().getIdentifier("ic_charge_socket_" + socket.type(), "drawable",
|
int resIconId = getResources().getIdentifier("ic_charge_socket_" + socket.visualType(), "drawable",
|
||||||
requireContext().getPackageName());
|
requireContext().getPackageName());
|
||||||
if (resIconId != 0)
|
if (resIconId != 0)
|
||||||
{
|
{
|
||||||
@@ -98,7 +100,7 @@ public class PlacePageChargeSocketsFragment extends Fragment implements Observer
|
|||||||
|
|
||||||
@SuppressLint("DiscouragedApi")
|
@SuppressLint("DiscouragedApi")
|
||||||
int resTypeId =
|
int resTypeId =
|
||||||
getResources().getIdentifier("charge_socket_" + socket.type(), "string", requireContext().getPackageName());
|
getResources().getIdentifier("charge_socket_" + socket.visualType(), "string", requireContext().getPackageName());
|
||||||
if (resTypeId != 0)
|
if (resTypeId != 0)
|
||||||
{
|
{
|
||||||
type.setText(resTypeId);
|
type.setText(resTypeId);
|
||||||
@@ -109,6 +111,9 @@ public class PlacePageChargeSocketsFragment extends Fragment implements Observer
|
|||||||
DecimalFormat df = new DecimalFormat("#.##");
|
DecimalFormat df = new DecimalFormat("#.##");
|
||||||
power.setText(getString(R.string.kw_label, df.format(socket.power())));
|
power.setText(getString(R.string.kw_label, df.format(socket.power())));
|
||||||
}
|
}
|
||||||
|
else if (socket.ignorePower()) {
|
||||||
|
power.setVisibility(INVISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
if (socket.count() != 0)
|
if (socket.count() != 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -887,6 +887,7 @@
|
|||||||
<string name="charge_socket_power">Potencia (kW)</string>
|
<string name="charge_socket_power">Potencia (kW)</string>
|
||||||
<string name="unknown_count">desconocido</string>
|
<string name="unknown_count">desconocido</string>
|
||||||
<string name="avoid_steps">Evitar escaleras</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="unknown_socket_type">enchufe desconocido</string>
|
||||||
<string name="edit_socket_info_tooltip">Crear nuevo enchufe o editar existentes.</string>
|
<string name="edit_socket_info_tooltip">Crear nuevo enchufe o editar existentes.</string>
|
||||||
<string name="charging_station_available_sockets">Enchufes disponibles</string>
|
<string name="charging_station_available_sockets">Enchufes disponibles</string>
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
<item>type1</item>
|
<item>type1</item>
|
||||||
<item>type2_cable</item>
|
<item>type2_cable</item>
|
||||||
<item>type2</item>
|
<item>type2</item>
|
||||||
|
<item>schuko</item>
|
||||||
<item>unknown</item>
|
<item>unknown</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
|||||||
@@ -939,6 +939,7 @@
|
|||||||
<string name="charge_socket_type1">Type 1</string>
|
<string name="charge_socket_type1">Type 1</string>
|
||||||
<string name="charge_socket_nacs">NACS</string>
|
<string name="charge_socket_nacs">NACS</string>
|
||||||
<string name="charge_socket_chademo">CHAdeMO</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="unknown_socket_type">unknown socket</string>
|
||||||
<string name="edit_socket_info_tooltip">Create new sockets or edit existing ones.</string>
|
<string name="edit_socket_info_tooltip">Create new sockets or edit existing ones.</string>
|
||||||
<string name="charging_station_available_sockets">Available sockets</string>
|
<string name="charging_station_available_sockets">Available sockets</string>
|
||||||
|
|||||||
@@ -1,7 +1,33 @@
|
|||||||
package app.organicmaps.sdk.bookmarks.data;
|
package app.organicmaps.sdk.bookmarks.data;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* represents the details of the socket available on a particular charging station
|
* represents the details of the socket available on a particular charging station
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public record ChargeSocketDescriptor(String type, int count, double power) {}
|
public record ChargeSocketDescriptor(String type, int count, double power) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some charge sockets have the same visuals as other sockets, even though they are different and are tagged
|
||||||
|
* differently in OSM. This method returns the 'visual' type that should be used for the socket.
|
||||||
|
*
|
||||||
|
* @return the 'equivalent' visual style that should be used for this socket
|
||||||
|
*/
|
||||||
|
public String visualType() {
|
||||||
|
if (type.equals("typee")) {
|
||||||
|
return "schuko";
|
||||||
|
}
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For some sockets (eg, domestic sockets), the power is usually not provided, as it is 'implicit'
|
||||||
|
*
|
||||||
|
* @return true if this socket type does not require displaying the power
|
||||||
|
*/
|
||||||
|
public Boolean ignorePower() {
|
||||||
|
return type.equals("typee") || type.equals("schuko");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="32dp"
|
||||||
|
android:height="32dp"
|
||||||
|
android:viewportWidth="32"
|
||||||
|
android:viewportHeight="32">
|
||||||
|
<path
|
||||||
|
android:pathData="M16.847,0.853L16.847,2.125h-1.693L15.153,0.855A8.965,8.965 0,0 0,8.245 5.281L8.245,8.496L7.128,8.496a8.965,8.965 0,0 0,-0.094 1.283,8.965 8.965,0 0,0 0.092,1.283L8.245,11.062v3.217a8.965,8.965 0,0 0,6.908 4.426v-1.361h1.693v1.361a8.965,8.965 0,0 0,6.908 -4.426v-3.217h1.119a8.965,8.965 0,0 0,0.092 -1.283,8.965 8.965,0 0,0 -0.092,-1.283h-1.119L23.755,5.279A8.965,8.965 0,0 0,16.847 0.853ZM11.519,8.183c0.881,0 1.594,0.715 1.594,1.596 0,0.881 -0.713,1.596 -1.594,1.596C10.637,11.375 9.923,10.66 9.923,9.779 9.923,8.898 10.637,8.183 11.519,8.183ZM20.483,8.183c0.881,0 1.594,0.715 1.594,1.596 0,0.881 -0.713,1.596 -1.594,1.596 -0.881,0 -1.596,-0.714 -1.596,-1.596 0,-0.881 0.715,-1.596 1.596,-1.596z"
|
||||||
|
android:strokeWidth="0"
|
||||||
|
android:fillColor="#ffffff"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg
|
||||||
|
id="svg4"
|
||||||
|
viewBox="0 0 32 32"
|
||||||
|
height="32"
|
||||||
|
width="32"
|
||||||
|
version="1.1"
|
||||||
|
sodipodi:docname="ic_charge_socket_schuko.svg"
|
||||||
|
inkscape:version="1.4.2 (ebf0e940d0, 2025-05-08)"
|
||||||
|
xml:space="preserve"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"><sodipodi:namedview
|
||||||
|
id="namedview1"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#000000"
|
||||||
|
borderopacity="0.25"
|
||||||
|
inkscape:showpageshadow="2"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pagecheckerboard="0"
|
||||||
|
inkscape:deskcolor="#d1d1d1"
|
||||||
|
inkscape:zoom="9.6339353"
|
||||||
|
inkscape:cx="4.826688"
|
||||||
|
inkscape:cy="18.735853"
|
||||||
|
inkscape:window-width="1920"
|
||||||
|
inkscape:window-height="1131"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
inkscape:window-y="0"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg4"
|
||||||
|
showguides="true" /><metadata
|
||||||
|
id="metadata10"><rdf:RDF><cc:Work
|
||||||
|
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs
|
||||||
|
id="defs8" /><path
|
||||||
|
id="path3"
|
||||||
|
style="opacity:1;fill:#000000;fill-opacity:1;stroke-width:27.048"
|
||||||
|
d="M 16.846679,0.85321632 V 2.1247006 h -1.69336 V 0.85516952 A 8.9651508,8.9651508 0 0 0 8.2451158,5.2809506 V 8.495794 H 7.1279284 a 8.9651508,8.9651508 0 0 0 -0.09375,1.283204 8.9651508,8.9651508 0 0 0 0.091797,1.283203 H 8.245116 v 3.216797 a 8.9651508,8.9651508 0 0 0 6.908203,4.425781 v -1.361328 h 1.69336 v 1.361328 a 8.9651508,8.9651508 0 0 0 6.908203,-4.425781 v -3.216797 h 1.11914 a 8.9651508,8.9651508 0 0 0 0.0918,-1.283203 8.9651508,8.9651508 0 0 0 -0.0918,-1.283204 h -1.11914 V 5.2789975 A 8.9651508,8.9651508 0 0 0 16.846679,0.85321632 Z M 11.518554,8.183294 c 0.880948,1.55e-4 1.593598,0.714757 1.59375,1.595704 1.31e-4,0.881148 -0.712601,1.595548 -1.59375,1.595703 C 10.637202,11.374833 9.9227216,10.66035 9.9228506,9.778998 9.9230016,8.897849 10.637405,8.183163 11.518554,8.183294 Z m 8.964844,0 c 0.880948,1.55e-4 1.593598,0.714757 1.59375,1.595704 1.3e-4,0.881148 -0.712601,1.595548 -1.59375,1.595703 -0.881352,1.32e-4 -1.595833,-0.714351 -1.595704,-1.595703 1.51e-4,-0.881149 0.714554,-1.595835 1.595704,-1.595704 z" /></svg>
|
||||||
|
After Width: | Height: | Size: 2.5 KiB |
Reference in New Issue
Block a user