Skip to content

Commit

Permalink
Merge pull request #5301 from FloEdelmann/drop-mcc
Browse files Browse the repository at this point in the history
Drop MCC hack completely
  • Loading branch information
westnordost authored Oct 16, 2023
2 parents 6ae45b7 + a41126f commit c487d07
Show file tree
Hide file tree
Showing 35 changed files with 129 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,6 @@ abstract class AbstractQuestForm :
initialMapRotation = args.getFloat(ARG_MAP_ROTATION)
initialMapTilt = args.getFloat(ARG_MAP_TILT)
_countryInfo = null // reset lazy field

/* The Android resource system is not designed to offer different resources depending on the
* country (code). But what it can do is to offer different resources for different
* "mobile country codes" - i.e. in which country your mobile phone network provider
* operates.
*
* A few quest forms want to display different resources depending on the country.
*
* So what we do here is to override the parent activity's "mobile country code" resource
* configuration and use this mechanism to access our country-dependent resources */
countryInfo.mobileCountryCode?.let { activity?.resources?.updateConfiguration { mcc = it } }
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class AddMaxHeightForm : AbstractOsmQuestForm<MaxHeightAnswer>() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

view.findViewById<View?>(R.id.meterInputSign)
?.setBackgroundResource(getSignBackgroundDrawableResId(countryInfo.countryCode))
view.findViewById<View?>(R.id.feetInputSign)
?.setBackgroundResource(getSignBackgroundDrawableResId(countryInfo.countryCode))

val splitWayHint = view.findViewById<TextView>(R.id.splitWayHint)
splitWayHint?.text = getString(R.string.quest_maxheight_split_way_hint, getString(R.string.quest_generic_answer_differs_along_the_way))
splitWayHint?.isGone = element.type == ElementType.NODE
Expand Down Expand Up @@ -83,3 +88,8 @@ class AddMaxHeightForm : AbstractOsmQuestForm<MaxHeightAnswer>() {
}
}
}

private fun getSignBackgroundDrawableResId(countryCode: String): Int = when (countryCode) {
"FI", "IS", "SE" -> R.drawable.background_maxheight_sign_yellow
else -> R.drawable.background_maxheight_sign
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ class AddMaxSpeedForm : AbstractOsmQuestForm<MaxSpeedAnswer>() {
this.speedType = speedType

binding.rightSideContainer.removeAllViews()
speedType?.layoutResId?.let { layoutInflater.inflate(it, binding.rightSideContainer, true) }
speedType?.layoutResId?.let {
layoutInflater.inflate(it, binding.rightSideContainer, true)
binding.rightSideContainer.adjustProhibitionSignBackground(countryInfo.countryCode)
}

speedInput = binding.rightSideContainer.findViewById(R.id.maxSpeedInput)
speedInput?.doAfterTextChanged { checkIsFormComplete() }
Expand Down Expand Up @@ -228,6 +231,13 @@ class AddMaxSpeedForm : AbstractOsmQuestForm<MaxSpeedAnswer>() {
activity?.let {
val dialogBinding = QuestMaxspeedNoSignNoSlowZoneConfirmationBinding.inflate(layoutInflater)
enableAppropriateLabelsForSlowZone(dialogBinding.slowZoneImage)
dialogBinding.slowZoneImage.removeAllViews()
layoutInflater.inflate(
getMaxSpeedZoneSignLayoutResId(countryInfo.countryCode),
dialogBinding.slowZoneImage,
true,
)
dialogBinding.slowZoneImage.adjustProhibitionSignBackground(countryInfo.countryCode)
val dialogSpeedInput: EditText = dialogBinding.slowZoneImage.findViewById(R.id.maxSpeedInput)
dialogSpeedInput.setText("××")
dialogSpeedInput.inputType = EditorInfo.TYPE_NULL
Expand Down Expand Up @@ -335,3 +345,21 @@ private fun getMaxSpeedZoneSignLayoutResId(countryCode: String): Int = when (cou
"IL" -> R.layout.quest_maxspeed_zone_sign_il
else -> R.layout.quest_maxspeed_zone_sign
}

private fun View.adjustProhibitionSignBackground(countryCode: String) {
this.findViewById<View?>(R.id.genericProhibitionSign)
?.setBackgroundResource(getSignBackgroundDrawableResId(countryCode))

this.findViewById<View?>(R.id.maxSpeedSignNoFrame)
?.setBackgroundResource(getSignNoFrameBackgroundDrawableResId(countryCode))
}

private fun getSignBackgroundDrawableResId(countryCode: String): Int = when (countryCode) {
"FI", "IS", "SE" -> R.drawable.background_generic_prohibition_sign_yellow
else -> R.drawable.background_generic_prohibition_sign
}

private fun getSignNoFrameBackgroundDrawableResId(countryCode: String): Int = when (countryCode) {
"FI", "IS", "SE" -> R.drawable.background_maxspeed_sign_no_frame_small_yellow
else -> R.drawable.background_maxspeed_sign_no_frame_small
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ private fun MaxWeightSign.createBitmap(inflater: LayoutInflater, countryCode: St
)
inflater.inflate(getLayoutResourceId(countryCode), container)

container.findViewById<View?>(R.id.genericProhibitionSign)
?.setBackgroundResource(getSignBackgroundDrawableResId(countryCode))

container.measure(
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
Expand All @@ -52,23 +55,28 @@ fun MaxWeightSign.getLayoutResourceId(countryCode: String) = when (this) {
}

private fun getMaxWeightSignLayoutResId(countryCode: String): Int = when (countryCode) {
"AU", "CA", "US" -> R.layout.quest_maxweight_us_sign
else -> R.layout.quest_maxweight_sign
"AU", "CA", "US" -> R.layout.quest_maxweight_sign_us
else -> R.layout.quest_maxweight_sign
}

private fun getMaxWeightMgvSignLayoutResId(countryCode: String): Int = when (countryCode) {
"AU", "CA", "US" -> R.layout.quest_maxweight_mgv_us_sign
"DE" -> R.layout.quest_maxweight_mgv_de_sign
"GB" -> R.layout.quest_maxweight_mgv_gb_sign
else -> R.layout.quest_maxweight_mgv_sign
"AU", "CA", "US" -> R.layout.quest_maxweight_mgv_sign_us
"DE" -> R.layout.quest_maxweight_mgv_sign_de
"GB" -> R.layout.quest_maxweight_mgv_sign_gb
else -> R.layout.quest_maxweight_mgv_sign
}

private fun getMaxWeightAxleLoadSignLayoutResId(countryCode: String): Int = when (countryCode) {
"AU", "CA", "US" -> R.layout.quest_maxweight_axleload_us_sign
else -> R.layout.quest_maxweight_axleload_sign
"AU", "CA", "US" -> R.layout.quest_maxweight_axleload_sign_us
else -> R.layout.quest_maxweight_axleload_sign
}

private fun getMaxWeightTandemAxleLoadSignLayoutResId(countryCode: String): Int = when (countryCode) {
"AU", "CA", "US" -> R.layout.quest_maxweight_tandem_axleload_us_sign
else -> R.layout.quest_maxweight_tandem_axleload_sign
"AU", "CA", "US" -> R.layout.quest_maxweight_tandem_axleload_sign_us
else -> R.layout.quest_maxweight_tandem_axleload_sign
}

private fun getSignBackgroundDrawableResId(countryCode: String): Int = when (countryCode) {
"FI", "IS", "SE" -> R.drawable.background_generic_prohibition_sign_yellow
else -> R.drawable.background_generic_prohibition_sign
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package de.westnordost.streetcomplete.quests.traffic_signals_vibrate

import android.os.Bundle
import android.view.View
import android.widget.ImageView
import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.quests.AbstractOsmQuestForm
import de.westnordost.streetcomplete.quests.AnswerItem
Expand All @@ -8,8 +11,21 @@ class AddTrafficSignalsVibrationForm : AbstractOsmQuestForm<Boolean>() {

override val contentLayoutResId = R.layout.quest_traffic_lights_vibration

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

view.findViewById<ImageView>(R.id.buttonIllustrationImageView)
.setImageResource(getVibratingButtonIllustrationResId(countryInfo.countryCode))
}

override val buttonPanelAnswers = listOf(
AnswerItem(R.string.quest_generic_hasFeature_no) { applyAnswer(false) },
AnswerItem(R.string.quest_generic_hasFeature_yes) { applyAnswer(true) }
)
}

private fun getVibratingButtonIllustrationResId(countryCode: String): Int = when (countryCode) {
"AU" -> R.drawable.vibrating_button_illustration_au
"GB" -> R.drawable.vibrating_button_illustration_gb
else -> R.drawable.vibrating_button_illustration
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/traffic_sign_background"/>
<solid android:color="@color/traffic_white"/>
</shape>
</item>
<item android:top="2dp" android:left="2dp" android:bottom="2dp" android:right="2dp">
Expand All @@ -12,7 +12,7 @@
</item>
<item android:top="16dp" android:left="16dp" android:bottom="16dp" android:right="16dp">
<shape android:shape="oval">
<solid android:color="@color/traffic_sign_background"/>
<solid android:color="@color/traffic_white"/>
</shape>
</item>
</layer-list>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/traffic_yellow"/>
</shape>
</item>
<item android:top="2dp" android:left="2dp" android:bottom="2dp" android:right="2dp">
<shape android:shape="oval">
<solid android:color="@color/traffic_red"/>
</shape>
</item>
<item android:top="16dp" android:left="16dp" android:bottom="16dp" android:right="16dp">
<shape android:shape="oval">
<solid android:color="@color/traffic_yellow"/>
</shape>
</item>
</layer-list>
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/background_maxheight_sign.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:viewportHeight="112">
<path
android:pathData="M56,56m-55.75,0a55.75,55.75 0,1 1,111.5 0a55.75,55.75 0,1 1,-111.5 0"
android:fillColor="@color/traffic_sign_background"/>
android:fillColor="@color/traffic_white"/>
<path
android:pathData="M56,34 l-18,-18h36zM56,78 l18,18L38,96Z"
android:fillColor="@color/traffic_black"/>
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/background_maxheight_sign_yellow.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="112dp"
android:height="112dp"
android:viewportWidth="112"
android:viewportHeight="112">
<path
android:pathData="M56,56m-55.75,0a55.75,55.75 0,1 1,111.5 0a55.75,55.75 0,1 1,-111.5 0"
android:fillColor="@color/traffic_yellow"/>
<path
android:pathData="M56,34 l-18,-18h36zM56,78 l18,18L38,96Z"
android:fillColor="@color/traffic_black"/>
<path
android:pathData="m56,2a54,54 0,0 0,-54 54,54 54,0 0,0 54,54 54,54 0,0 0,54 -54,54 54,0 0,0 -54,-54zM56,16a40,40 0,0 1,40 40,40 40,0 0,1 -40,40 40,40 0,0 1,-40 -40,40 40,0 0,1 40,-40z"
android:fillColor="@color/traffic_red"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</item>
<item android:top="10dp" android:left="10dp" android:bottom="10dp" android:right="10dp">
<shape android:shape="oval">
<solid android:color="@color/traffic_sign_background"/>
<solid android:color="@color/traffic_white"/>
</shape>
</item>
</layer-list>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/traffic_red"/>
</shape>
</item>
<item android:top="10dp" android:left="10dp" android:bottom="10dp" android:right="10dp">
<shape android:shape="oval">
<solid android:color="@color/traffic_yellow"/>
</shape>
</item>
</layer-list>
1 change: 1 addition & 0 deletions app/src/main/res/layout/quest_maxspeed_sign.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="112dp"
android:layout_height="112dp"
android:id="@+id/genericProhibitionSign"
android:background="@drawable/background_generic_prohibition_sign"
android:paddingStart="16dp"
android:paddingEnd="16dp"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/quest_maxspeed_zone_sign.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<LinearLayout
android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/maxSpeedSignNoFrame"
android:background="@drawable/background_maxspeed_sign_no_frame_small"
android:paddingStart="12dp"
android:paddingEnd="12dp"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/quest_maxweight_axleload_sign.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
android:layout_width="112dp"
android:layout_height="112dp"
android:gravity="center"
android:id="@+id/genericProhibitionSign"
android:background="@drawable/background_generic_prohibition_sign"
android:layout_centerInParent="true"
android:padding="18dp"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/quest_maxweight_mgv_sign.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="112dp"
android:layout_height="112dp"
android:id="@+id/genericProhibitionSign"
android:background="@drawable/background_generic_prohibition_sign"
android:padding="22dp"
android:gravity="center"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/quest_maxweight_sign.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="112dp"
android:layout_height="112dp"
android:id="@+id/genericProhibitionSign"
android:background="@drawable/background_generic_prohibition_sign"
android:padding="22dp"
android:orientation="horizontal"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="112dp"
android:layout_height="112dp"
android:id="@+id/genericProhibitionSign"
android:background="@drawable/background_generic_prohibition_sign"
android:padding="22dp"
android:gravity="center"
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/res/values-mcc240/colors.xml

This file was deleted.

4 changes: 0 additions & 4 deletions app/src/main/res/values-mcc244/colors.xml

This file was deleted.

4 changes: 0 additions & 4 deletions app/src/main/res/values-mcc274/colors.xml

This file was deleted.

2 changes: 0 additions & 2 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@

<color name="smoothness_vehicle_tyre">#292f33</color>

<color name="traffic_sign_background">@color/traffic_white</color>

<color name="pressed">#ddd</color>

<color name="disabled_notice">#66999999</color>
Expand Down

0 comments on commit c487d07

Please sign in to comment.