mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-06 12:34:24 +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;
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
<item>type1</item>
|
||||
<item>type2_cable</item>
|
||||
<item>type2</item>
|
||||
<item>schuko</item>
|
||||
<item>unknown</item>
|
||||
</string-array>
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -1,7 +1,33 @@
|
||||
package app.organicmaps.sdk.bookmarks.data;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
Reference in New Issue
Block a user