[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge pull request #214 from mohamedamir/master
Browse files Browse the repository at this point in the history
(AUTOMATIC) opensource update
  • Loading branch information
sockix committed Apr 19, 2021
2 parents 2298010 + c352cef commit 8a44b7e
Show file tree
Hide file tree
Showing 18 changed files with 184 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import androidx.test.platform.app.InstrumentationRegistry;
import com.android.i18n.addressinput.AddressAutocompleteController.AddressAdapter;
import com.android.i18n.addressinput.AddressAutocompleteController.AddressPrediction;
import com.android.i18n.addressinput.testing.TestActivity;
Expand Down Expand Up @@ -76,9 +77,16 @@ protected void setUp() {
context = getActivity();

textView = new AutoCompleteTextView(context);
controller =
new AddressAutocompleteController(context, autocompleteApi, placeDetailsApi)
.setView(textView);
InstrumentationRegistry.getInstrumentation()
.runOnMainSync(
new Runnable() {
@Override
public void run() {
controller =
new AddressAutocompleteController(context, autocompleteApi, placeDetailsApi)
.setView(textView);
}
});
}

// Tests for the AddressAutocompleteController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import androidx.test.platform.app.InstrumentationRegistry;
import com.android.i18n.addressinput.testing.TestActivity;
import com.google.i18n.addressinput.common.AddressData;
import com.google.i18n.addressinput.common.AddressField;
Expand Down Expand Up @@ -65,14 +66,21 @@ public void testCustomWidgets() {
customTextViewCounter = 0;
customProgressDialogCounter = 0;
componentProvider = new TestComponentProvider(context);
widget =
new AddressWidget(
context,
container,
new FormOptions(),
new SimpleClientCacheManager(),
componentProvider);
widget.renderFormWithSavedAddress(address);
InstrumentationRegistry.getInstrumentation()
.runOnMainSync(
new Runnable() {
@Override
public void run() {
widget =
new AddressWidget(
context,
container,
new FormOptions(),
new SimpleClientCacheManager(),
componentProvider);
widget.renderFormWithSavedAddress(address);
}
});

for (AddressField field : AddressField.values()) {
if (field.equals(AddressField.COUNTRY)) {
Expand Down Expand Up @@ -102,14 +110,21 @@ public void testDisplayAndClearingOfErrorMessages() {
customTextViewCounter = 0;
customProgressDialogCounter = 0;
componentProvider = new TestComponentProvider(context);
widget =
new AddressWidget(
context,
container,
new FormOptions(),
new SimpleClientCacheManager(),
componentProvider);
widget.renderFormWithSavedAddress(address);
InstrumentationRegistry.getInstrumentation()
.runOnMainSync(
new Runnable() {
@Override
public void run() {
widget =
new AddressWidget(
context,
container,
new FormOptions(),
new SimpleClientCacheManager(),
componentProvider);
widget.renderFormWithSavedAddress(address);
}
});

EditText streetAddressView = (EditText) widget.getViewForField(AddressField.STREET_ADDRESS);
EditText addressLine1View = (EditText) widget.getViewForField(AddressField.ADDRESS_LINE_1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.android.i18n.addressinput;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package com.android.i18n.addressinput.autocomplete.gmscore;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ of autocomplete dropdown items to darken when they are clicked.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid android:drawable="@color/ripple_material_light"/>
<solid android:drawable="@color/androidx_core_ripple_material_light"/>
</shape>
</item>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
-->
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/ripple_material_light">
android:color="@color/androidx_core_ripple_material_light">

<item android:drawable="@android:color/white" />
</ripple>
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public boolean equals(Object o) {
? addressData.getRecipient() == null
: recipient.equals(addressData.getRecipient()))
&& (languageCode == null
? this.getLanguageCode() == null
? addressData.getLanguageCode() == null
: languageCode.equals(addressData.getLanguageCode()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ public enum AddressDataKey {
* level below country.
*/
ZIP,
/**
* Indicates the type of the name used for the ZIP (postal code) field.
*/
ZIP_NAME_TYPE;
/** Indicates the type of the name used for the ZIP (postal code) field. */
ZIP_NAME_TYPE,
/** Common prefix for postal code. */
POSTPREFIX,
/** Helper URL for postal code. */
POSTURL;

/**
* Returns a field based on its keyname (value in the JSON-format file), or null if no field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private static Map<String, String> createMap() {
map.put("BT", "{\"name\":\"BHUTAN\",\"fmt\":\"%N%n%O%n%A%n%C %Z\"}");
map.put("BV", "{\"name\":\"BOUVET ISLAND\"}");
map.put("BW", "{\"name\":\"BOTSWANA\"}");
map.put("BY", "{\"name\":\"BELARUS\",\"fmt\":\"%S%n%Z %C%n%A%n%O%n%N\"}");
map.put("BY", "{\"name\":\"BELARUS\",\"fmt\":\"%O%n%N%n%A%n%Z, %C%n%S\"}");
map.put("BZ", "{\"name\":\"BELIZE\"}");
map.put("CA", "{\"name\":\"CANADA\",\"lang\":\"en\",\"languages\":\"en~fr\",\"fmt\":\"%N%n%O%n%A%n%C %S %Z\",\"require\":\"ACSZ\",\"upper\":\"ACNOSZ\"}");
map.put("CC", "{\"name\":\"COCOS (KEELING) ISLANDS\",\"fmt\":\"%O%n%N%n%A%n%C %S %Z\",\"upper\":\"CS\"}");
Expand Down Expand Up @@ -130,12 +130,12 @@ private static Map<String, String> createMap() {
map.put("GY", "{\"name\":\"GUYANA\"}");
map.put("HK", "{\"name\":\"HONG KONG\",\"lang\":\"zh-Hant\",\"languages\":\"zh-Hant~en\",\"lfmt\":\"%N%n%O%n%A%n%C%n%S\",\"fmt\":\"%S%n%C%n%A%n%O%n%N\",\"require\":\"AS\",\"upper\":\"S\",\"locality_name_type\":\"district\",\"state_name_type\":\"area\",\"width_overrides\":\"%S:S%C:L\",\"label_overrides\":[{\"field\":\"C\",\"label\":\"地区\",\"lang\":\"zh\"},{\"field\":\"C\",\"label\":\"地區\",\"lang\":\"zh-HK\"},{\"field\":\"C\",\"label\":\"地區\",\"lang\":\"zh-TW\"},{\"field\":\"CS\",\"label\":\"Flat / Room\",\"lang\":\"en\"},{\"field\":\"CS\",\"label\":\"單位編號\",\"lang\":\"zh-HK\"},{\"field\":\"BG\",\"label\":\"大廈名稱\",\"lang\":\"zh-HK\"}]}");
map.put("HM", "{\"name\":\"HEARD AND MCDONALD ISLANDS\",\"fmt\":\"%O%n%N%n%A%n%C %S %Z\",\"upper\":\"CS\"}");
map.put("HN", "{\"name\":\"HONDURAS\",\"fmt\":\"%N%n%O%n%A%n%C, %S%n%Z\",\"require\":\"ACS\"}");
map.put("HN", "{\"name\":\"HONDURAS\",\"fmt\":\"%N%n%O%n%A%n%C, %S%n%Z\",\"require\":\"ACS\",\"state_name_type\":\"department\"}");
map.put("HR", "{\"name\":\"CROATIA\",\"fmt\":\"%N%n%O%n%A%nHR-%Z %C\",\"postprefix\":\"HR-\"}");
map.put("HT", "{\"name\":\"HAITI\",\"fmt\":\"%N%n%O%n%A%nHT%Z %C\",\"postprefix\":\"HT\"}");
map.put("HU", "{\"name\":\"HUNGARY (Rep.)\",\"fmt\":\"%N%n%O%n%C%n%A%n%Z\",\"require\":\"ACZ\",\"upper\":\"ACNO\"}");
map.put("ID", "{\"name\":\"INDONESIA\",\"lang\":\"id\",\"languages\":\"id\",\"fmt\":\"%N%n%O%n%A%n%C%n%S %Z\",\"require\":\"AS\",\"label_overrides\":[{\"field\":\"A7\",\"label\":\"RT\"},{\"field\":\"A6\",\"label\":\"RW\"},{\"field\":\"A5\",\"label\":\"Dusun/Banjar\"},{\"field\":\"BI\",\"label\":\"Blok\"},{\"field\":\"A4\",\"message\":\"MSG_VILLAGE\"},{\"field\":\"A3\",\"label\":\"Kecamatan\"},{\"field\":\"S1\",\"label\":\"Pasar\"}]}");
map.put("IE", "{\"name\":\"IRELAND\",\"lang\":\"en\",\"languages\":\"en\",\"fmt\":\"%N%n%O%n%A%n%D%n%C%n%S %Z\",\"sublocality_name_type\":\"townland\",\"state_name_type\":\"county\",\"zip_name_type\":\"eircode\",\"label_overrides\":[{\"field\":\"S\",\"label\":\"\",\"lang\":\"zh\"}]}");
map.put("IE", "{\"name\":\"IRELAND\",\"lang\":\"en\",\"languages\":\"en\",\"fmt\":\"%N%n%O%n%A%n%D%n%C%n%S%n%Z\",\"sublocality_name_type\":\"townland\",\"state_name_type\":\"county\",\"zip_name_type\":\"eircode\",\"label_overrides\":[{\"field\":\"S\",\"label\":\"\",\"lang\":\"zh\"}]}");
map.put("IL", "{\"name\":\"ISRAEL\",\"fmt\":\"%N%n%O%n%A%n%C %Z\"}");
map.put("IM", "{\"name\":\"ISLE OF MAN\",\"fmt\":\"%N%n%O%n%A%n%C%n%Z\",\"require\":\"ACZ\",\"upper\":\"CZ\"}");
map.put("IN", "{\"name\":\"INDIA\",\"lang\":\"en\",\"languages\":\"en~hi\",\"fmt\":\"%N%n%O%n%A%n%C %Z%n%S\",\"require\":\"ACSZ\",\"state_name_type\":\"state\",\"zip_name_type\":\"pin\",\"label_overrides\":[{\"field\":\"S1\",\"label\":\"Sublocality 1\"},{\"field\":\"S2\",\"label\":\"Sublocality 2\"},{\"field\":\"S3\",\"label\":\"Sublocality 3\"},{\"field\":\"S4\",\"label\":\"Sublocality 4\"}]}");
Expand Down Expand Up @@ -193,7 +193,7 @@ private static Map<String, String> createMap() {
map.put("MX", "{\"name\":\"MEXICO\",\"lang\":\"es\",\"languages\":\"es\",\"fmt\":\"%N%n%O%n%A%n%D%n%Z %C, %S\",\"require\":\"ACSZ\",\"upper\":\"CSZ\",\"sublocality_name_type\":\"neighborhood\",\"state_name_type\":\"state\",\"width_overrides\":\"%S:S\",\"label_overrides\":[{\"field\":\"S1\",\"label\":\"Delegación\"},{\"field\":\"S2\",\"label\":\"Supermanzana\"},{\"field\":\"S3\",\"label\":\"Manzana\"},{\"field\":\"LP\",\"label\":\"Lote\"}]}");
map.put("MY", "{\"name\":\"MALAYSIA\",\"lang\":\"ms\",\"languages\":\"ms\",\"fmt\":\"%N%n%O%n%A%n%D%n%Z %C%n%S\",\"require\":\"ACZ\",\"upper\":\"CS\",\"sublocality_name_type\":\"village_township\",\"state_name_type\":\"state\"}");
map.put("MZ", "{\"name\":\"MOZAMBIQUE\",\"lang\":\"pt\",\"languages\":\"pt\",\"fmt\":\"%N%n%O%n%A%n%Z %C%S\"}");
map.put("NA", "{\"name\":\"NAMIBIA\",\"fmt\":\"%N%n%O%n%A%n%Cn%Z\"}");
map.put("NA", "{\"name\":\"NAMIBIA\",\"fmt\":\"%N%n%O%n%A%n%C%n%Z\"}");
map.put("NC", "{\"name\":\"NEW CALEDONIA\",\"fmt\":\"%O%n%N%n%A%n%Z %C %X\",\"require\":\"ACZ\",\"upper\":\"ACX\"}");
map.put("NE", "{\"name\":\"NIGER\",\"fmt\":\"%N%n%O%n%A%n%Z %C\"}");
map.put("NF", "{\"name\":\"NORFOLK ISLAND\",\"fmt\":\"%O%n%N%n%A%n%C %S %Z\",\"upper\":\"CS\"}");
Expand Down Expand Up @@ -264,7 +264,7 @@ private static Map<String, String> createMap() {
map.put("TV", "{\"name\":\"TUVALU\",\"lang\":\"tyv\",\"languages\":\"tyv\",\"fmt\":\"%N%n%O%n%A%n%C%n%S\",\"upper\":\"ACS\",\"state_name_type\":\"island\"}");
map.put("TW", "{\"name\":\"TAIWAN\",\"lang\":\"zh-Hant\",\"languages\":\"zh-Hant\",\"lfmt\":\"%N%n%O%n%A%n%C, %S %Z\",\"fmt\":\"%Z%n%S%C%n%A%n%O%n%N\",\"require\":\"ACSZ\",\"state_name_type\":\"county\"}");
map.put("TZ", "{\"name\":\"TANZANIA (UNITED REP.)\",\"fmt\":\"%N%n%O%n%A%n%Z %C\"}");
map.put("UA", "{\"name\":\"UKRAINE\",\"lang\":\"uk\",\"languages\":\"uk\",\"lfmt\":\"%N%n%O%n%A%n%C%n%S%n%Z\",\"fmt\":\"%N%n%O%n%A%n%C%n%S%n%Z\",\"require\":\"ACSZ\",\"state_name_type\":\"oblast\",\"label_overrides\":[{\"field\":\"CS\",\"message\":\"MSG_OFFICE_UNIT_NUMBER\"}]}");
map.put("UA", "{\"name\":\"UKRAINE\",\"lang\":\"uk\",\"languages\":\"uk\",\"lfmt\":\"%N%n%O%n%A%n%C%n%S%n%Z\",\"fmt\":\"%N%n%O%n%A%n%C%n%S%n%Z\",\"require\":\"ACZ\",\"state_name_type\":\"oblast\",\"label_overrides\":[{\"field\":\"CS\",\"message\":\"MSG_OFFICE_UNIT_NUMBER\"}]}");
map.put("UG", "{\"name\":\"UGANDA\"}");
map.put("UM", "{\"name\":\"UNITED STATES MINOR OUTLYING ISLANDS\",\"fmt\":\"%N%n%O%n%A%n%C %S %Z\",\"require\":\"ACS\",\"upper\":\"ACNOS\",\"state_name_type\":\"state\",\"zip_name_type\":\"zip\"}");
map.put("US", "{\"name\":\"UNITED STATES\",\"lang\":\"en\",\"languages\":\"en\",\"fmt\":\"%N%n%O%n%A%n%C, %S %Z\",\"require\":\"ACSZ\",\"upper\":\"CS\",\"state_name_type\":\"state\",\"zip_name_type\":\"zip\",\"width_overrides\":\"%S:S\"}");
Expand Down
6 changes: 6 additions & 0 deletions cpp/include/libaddressinput/address_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ std::vector<AddressUiComponent> BuildComponents(
const std::string& ui_language_tag,
std::string* best_address_language_tag);

// Similar to BuildComponents() but in addition, it returns any non-newline
// literals such as "-", " " and ",".
std::vector<AddressUiComponent> BuildComponentsWithLiterals(
const std::string& region_code, const Localization& localization,
const std::string& ui_language_tag, std::string* best_address_language_tag);

} // namespace addressinput
} // namespace i18n

Expand Down
12 changes: 10 additions & 2 deletions cpp/include/libaddressinput/address_ui_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
namespace i18n {
namespace addressinput {

// A description of an input field in an address form. The user of the library
// will use a list of these elements to layout the address form input fields.
// A description of an input field or a literal in an address form. The user of
// the library will use a list of these elements to layout the address form
// input fields. If `literal` is empty, this AddressUiComponent represents a
// field, otherwise, it represent the literal stored in `literal`.
struct AddressUiComponent {
// The types of hints for how large the field should be in a multiline address
// form.
Expand All @@ -41,6 +43,12 @@ struct AddressUiComponent {
// The hint for how large the input field should be in a multiline address
// form.
LengthHint length_hint;

// The literal string for this element. New lines are *not* captured by this
// field but are reflected in the `length_hint` field. This field is dedicated
// for other literals such as "," "-" and " ". If empty, then this
// AddressUiComponent represents an address field type not a literal.
std::string literal;
};

} // namespace addressinput
Expand Down
48 changes: 34 additions & 14 deletions cpp/src/address_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,9 @@ std::string GetLabelForField(const Localization& localization,
return localization.GetString(message_id);
}

} // namespace

const std::vector<std::string>& GetRegionCodes() {
return RegionDataConstants::GetRegionCodes();
}

std::vector<AddressUiComponent> BuildComponents(
const std::string& region_code,
const Localization& localization,
const std::string& ui_language_tag,
const std::string& region_code, const Localization& localization,
const std::string& ui_language_tag, bool include_literals,
std::string* best_address_language_tag) {
assert(best_address_language_tag != nullptr);
std::vector<AddressUiComponent> result;
Expand All @@ -98,7 +91,7 @@ std::vector<AddressUiComponent> BuildComponents(
return result;
}

const Language& best_address_language =
const Language best_address_language =
ChooseBestAddressLanguage(rule, Language(ui_language_tag));
*best_address_language_tag = best_address_language.tag;

Expand All @@ -115,11 +108,16 @@ std::vector<AddressUiComponent> BuildComponents(
bool followed_by_newline = true;
for (auto format_it = format.begin();
format_it != format.end(); ++format_it) {
if (format_it->IsNewline()) {
preceded_by_newline = true;
if (!format_it->IsField()) {
// This is a literal
if (include_literals) {
AddressUiComponent component;
component.literal = format_it->GetLiteral();
result.push_back(component);
}
if (format_it->IsNewline()) preceded_by_newline = true;
continue;
} else if (!format_it->IsField() ||
!fields.insert(format_it->GetField()).second) {
} else if (!fields.insert(format_it->GetField()).second) {
continue;
}
AddressUiComponent component;
Expand All @@ -143,5 +141,27 @@ std::vector<AddressUiComponent> BuildComponents(
return result;
}

} // namespace

const std::vector<std::string>& GetRegionCodes() {
return RegionDataConstants::GetRegionCodes();
}

std::vector<AddressUiComponent> BuildComponents(
const std::string& region_code, const Localization& localization,
const std::string& ui_language_tag,
std::string* best_address_language_tag) {
return BuildComponents(region_code, localization, ui_language_tag,
/*include_literals=*/false, best_address_language_tag);
}

std::vector<AddressUiComponent> BuildComponentsWithLiterals(
const std::string& region_code, const Localization& localization,
const std::string& ui_language_tag,
std::string* best_address_language_tag) {
return BuildComponents(region_code, localization, ui_language_tag,
/*include_literals=*/true, best_address_language_tag);
}

} // namespace addressinput
} // namespace i18n
2 changes: 1 addition & 1 deletion cpp/src/ondemand_supplier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void OndemandSupplier::Supply(const LookupKey& lookup_key,
RegionDataConstants::GetMaxLookupKeyDepth(lookup_key.GetRegionCode()));

for (size_t depth = 0; depth <= max_depth; ++depth) {
const std::string& key = lookup_key.ToKeyString(depth);
const std::string key = lookup_key.ToKeyString(depth);
auto it = rule_cache_.find(key);
if (it != rule_cache_.end()) {
task->hierarchy_.rule[depth] = it->second;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/preload_supplier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ const Rule* PreloadSupplier::GetRule(const LookupKey& lookup_key) const {

void PreloadSupplier::LoadRules(const std::string& region_code,
const Callback& loaded) {
const std::string& key = KeyFromRegionCode(region_code);
const std::string key = KeyFromRegionCode(region_code);

if (IsLoadedKey(key)) {
loaded(true, region_code, 0);
Expand Down Expand Up @@ -343,7 +343,7 @@ bool PreloadSupplier::GetRuleHierarchy(const LookupKey& lookup_key,
RegionDataConstants::GetMaxLookupKeyDepth(lookup_key.GetRegionCode()));

for (size_t depth = 0; depth <= max_depth; ++depth) {
const std::string& key = lookup_key.ToKeyString(depth);
const std::string key = lookup_key.ToKeyString(depth);
const Rule* rule = nullptr;
auto it = rule_index_->find(key);
if (it != rule_index_->end()) {
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/region_data_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void BuildRegionTreeRecursively(
LookupKey lookup_key;
for (const auto& key : keys) {
lookup_key.FromLookupKey(parent_key, key);
const std::string& lookup_key_string =
const std::string lookup_key_string =
lookup_key.ToKeyString(kLookupKeysMaxDepth);

++hint;
Expand Down Expand Up @@ -158,7 +158,7 @@ const RegionData& RegionDataBuilder::Build(
Rule rule;
rule.ParseSerializedRule(RegionDataConstants::GetRegionData(region_code));
static const Language kUndefinedLanguage("und");
const Language& best_language =
const Language best_language =
rule.GetLanguages().empty()
? kUndefinedLanguage
: ChooseBestAddressLanguage(rule, Language(ui_language_tag));
Expand Down
Loading

0 comments on commit 8a44b7e

Please sign in to comment.