Skip to content

Commit

Permalink
Merge pull request #1149 from westnordost/maxspeed-redesign
Browse files Browse the repository at this point in the history
Maxspeed redesign (#1085, #1133)
  • Loading branch information
westnordost authored Aug 5, 2018
2 parents 26c28e1 + 310a830 commit 1061a3f
Show file tree
Hide file tree
Showing 63 changed files with 1,235 additions and 1,155 deletions.
1 change: 1 addition & 0 deletions app/src/main/assets/country_metadata/AZ.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Do not edit. Source files are in /res/country_metadata
isLivingStreetKnown: true
mobileCountryCode: 400
officialLanguages: [az]
orchardProduces: [apple, tomatoe, hazelnut, grape, persimmon, pear, chilli_pepper, sweet_pepper, plum,
Expand Down
1 change: 1 addition & 0 deletions app/src/main/assets/country_metadata/IL.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Do not edit. Source files are in /res/country_metadata
additionalStreetsignLanguages: [en]
firstDayOfWorkweek: Su
isLivingStreetKnown: true
isSlowZoneKnown: true
mobileCountryCode: 425
officialLanguages: [heb, ar]
Expand Down
1 change: 1 addition & 0 deletions app/src/main/assets/country_metadata/MU.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Do not edit. Source files are in /res/country_metadata
isLeftHandTraffic: true
isLivingStreetKnown: true
isSlowZoneKnown: true
mobileCountryCode: 617
officialLanguages: [en, fr, mfe]
orchardProduces: [tomatoe, tea, pineapple, coconut, banana, chilli_pepper, sweet_pepper]
Expand Down
1 change: 1 addition & 0 deletions app/src/main/assets/country_metadata/NZ.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
isAdvisorySpeedLimitKnown: true
isLeftHandTraffic: true
isLivingStreetKnown: true
isSlowZoneKnown: true
mobileCountryCode: 530
officialLanguages: [en]
orchardProduces: [grape, kiwi, apple, avocado, peach, tomatoe, orange, cherry, blueberry, pear, walnut,
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/assets/country_metadata/US-NY.yml

This file was deleted.

1 change: 1 addition & 0 deletions app/src/main/assets/country_metadata/US.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Do not edit. Source files are in /res/country_metadata
isAdvisorySpeedLimitKnown: true
isSlowZoneKnown: false
mobileCountryCode: 310
officialLanguages: [en]
orchardProduces: [grape, almond, tomatoe, apple, walnut, pistachio, peach, blueberry, grapefruit, plum,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.westnordost.streetcomplete.quests;

import android.content.ContextWrapper;
import android.support.annotation.AnyThread;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.content.Context;
import android.content.res.Configuration;
Expand All @@ -16,8 +18,7 @@
import android.widget.PopupMenu;
import android.widget.TextView;

import org.xmlpull.v1.XmlPullParser;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -64,6 +65,9 @@ public abstract class AbstractQuestAnswerFragment extends AbstractBottomSheetFra

private List<OtherAnswer> otherAnswers;

private WeakReference<Context> currentContext = new WeakReference<>(null);
private ContextWrapper currentCountryContext;

public AbstractQuestAnswerFragment()
{
super();
Expand All @@ -76,13 +80,6 @@ public AbstractQuestAnswerFragment()
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
osmElement = (OsmElement) getArguments().getSerializable(ARG_ELEMENT);
elementGeometry = (ElementGeometry) getArguments().getSerializable(ARG_GEOMETRY);
questType = questTypeRegistry.getByName(getArguments().getString(ARG_QUESTTYPE));
countryInfo = null;
initialMapRotation = getArguments().getFloat(ARG_MAP_ROTATION);
initialMapTilt = getArguments().getFloat(ARG_MAP_TILT);

View view = inflater.inflate(R.layout.fragment_quest_answer, container, false);

TextView title = view.findViewById(R.id.title);
Expand Down Expand Up @@ -136,6 +133,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
{
super.onCreate(inState);
questAnswerComponent.onCreate(getArguments());
osmElement = (OsmElement) getArguments().getSerializable(ARG_ELEMENT);
elementGeometry = (ElementGeometry) getArguments().getSerializable(ARG_GEOMETRY);
questType = questTypeRegistry.getByName(getArguments().getString(ARG_QUESTTYPE));
countryInfo = null;
initialMapRotation = getArguments().getFloat(ARG_MAP_ROTATION);
initialMapTilt = getArguments().getFloat(ARG_MAP_TILT);
}

@Override public void onAttach(Context ctx)
Expand All @@ -144,6 +147,37 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
questAnswerComponent.onAttach((OsmQuestAnswerListener) ctx);
}

@NonNull @Override
public LayoutInflater onGetLayoutInflater(@Nullable Bundle savedInstanceState)
{
// will always return a layout inflater for the current country
return super.onGetLayoutInflater(savedInstanceState).cloneInContext(getContext());
}

@Override @Nullable public Context getContext()
{
Context context = super.getContext();
if(currentContext.get() != context)
{
currentContext = new WeakReference<>(context);
currentCountryContext = context != null ? createCurrentCountryContextWrapper(context) : null;
}
return currentCountryContext;
}

private ContextWrapper createCurrentCountryContextWrapper(Context context)
{
Configuration conf = new Configuration(context.getResources().getConfiguration());
Integer mcc = getCountryInfo().getMobileCountryCode();
conf.mcc = mcc != null ? mcc : 0;
Resources res = context.createConfigurationContext(conf).getResources();
return new ContextWrapper(context) {
@Override public Resources getResources()
{
return res;
}
};
}

protected final void onClickCantSay()
{
Expand All @@ -159,18 +193,10 @@ private Resources getEnglishResources()
{
Configuration conf = new Configuration(getResources().getConfiguration());
conf.setLocale(Locale.ENGLISH);
Context localizedContext = getActivity().createConfigurationContext(conf);
Context localizedContext = super.getContext().createConfigurationContext(conf);
return localizedContext.getResources();
}

protected final Resources getCurrentCountryResources()
{
Configuration conf = new Configuration(getResources().getConfiguration());
Integer mcc = getCountryInfo().getMobileCountryCode();
conf.mcc = mcc != null ? mcc : 0;
return getContext().createConfigurationContext(conf).getResources();
}

protected final void applyImmediateAnswer(Bundle data)
{
questAnswerComponent.onAnswerQuest(data);
Expand All @@ -187,16 +213,7 @@ protected final View setContentView(int resourceId)
{
content.removeAllViews();
}
return getActivity().getLayoutInflater().inflate(resourceId, content);
}

protected final View setContentView(XmlPullParser parser)
{
if(content.getChildCount() > 0)
{
content.removeAllViews();
}
return getActivity().getLayoutInflater().inflate(parser, content);
return LayoutInflater.from(getContext()).inflate(resourceId, content);
}

protected final View setButtonsView(int resourceId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private ListAdapter<Cycleway> createAdapter(List<Cycleway> items, final OnCyclew
ImageView iconView = itemView.findViewById(R.id.imageView);
TextView textView = itemView.findViewById(R.id.textView);
int resId = item.getIconResId(isLeftHandTraffic());
iconView.setImageDrawable(getCurrentCountryResources().getDrawable(resId));
iconView.setImageDrawable(getResources().getDrawable(resId));
textView.setText(item.nameResId);
itemView.setOnClickListener(view -> callback.onCyclewaySelected(item));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ else if (maxspeed != null)
{
boolean hasName = tags.containsKey("name");

if(hasName) return R.string.quest_maxspeed_name_title;
else return R.string.quest_maxspeed_title_short;
if(hasName) return R.string.quest_maxspeed_name_title2;
else return R.string.quest_maxspeed_title_short2;
}

@NonNull @Override public Countries getEnabledForCountries()
Expand Down
Loading

0 comments on commit 1061a3f

Please sign in to comment.