Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,56 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

--------------------------------------------------------------------------------

Copyright (c) 2013 The Chromium Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

--------------------------------------------------------------------------------

Copyright (c) 2010-2011, Tim Day <timday@timday.com>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

--------------------------------------------------------------------------------

This code implements the MD5 message-digest algorithm.
The algorithm is due to Ron Rivest. This code was
written by Colin Plumb in 1993, no copyright is claimed.
This code is in the public domain; do with it what you wish.
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public String getRegionDataKeyForValue(String value) {

private WidthType getFieldWidthType(AddressUiComponent field) {
// TODO(user): For drop-downs (spinners), derive the width-type from the list of values.
return field.getId().getWidthTypeForRegion(currentRegion);
return FormatInterpreter.getWidthTypeForRegion(field.getId(), currentRegion);
}

private void createView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ private static class AsyncHttp extends Thread {
private final int timeoutMillis;

protected AsyncHttp(URL requestUrl, AsyncCallback callback, int timeoutMillis) {
super("AddressInputAsyncHttp");
this.requestUrl = requestUrl;
this.callback = callback;
this.timeoutMillis = timeoutMillis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,24 +594,26 @@ public Builder(AddressData address) {
}

/**
* Sets the 2-letter CLDR region code of the address; see
* {@link AddressData#getPostalCountry()}. Unlike other values passed to the builder, the
* region code can never be null.
* Sets the 2-letter CLDR region code of the address; see {@link
* AddressData#getPostalCountry()}. Unlike other values passed to the builder, the region code
* can never be null.
*
* @param regionCode the CLDR region code of the address.
*/
// TODO: Rename to setRegionCode.
@CanIgnoreReturnValue
public Builder setCountry(String regionCode) {
return set(AddressField.COUNTRY, checkNotNull(regionCode));
}

/**
* Sets or clears the administrative area of the address; see
* {@link AddressData#getAdministrativeArea()}.
* Sets or clears the administrative area of the address; see {@link
* AddressData#getAdministrativeArea()}.
*
* @param adminAreaName the administrative area name, or null to clear an existing value.
*/
// TODO: Rename to setAdministrativeArea.
@CanIgnoreReturnValue
public Builder setAdminArea(String adminAreaName) {
return set(AddressField.ADMIN_AREA, adminAreaName);
}
Expand All @@ -621,16 +623,18 @@ public Builder setAdminArea(String adminAreaName) {
*
* @param locality the locality name, or null to clear an existing value.
*/
@CanIgnoreReturnValue
public Builder setLocality(String locality) {
return set(AddressField.LOCALITY, locality);
}

/**
* Sets or clears the dependent locality of the address; see
* {@link AddressData#getDependentLocality()}.
* Sets or clears the dependent locality of the address; see {@link
* AddressData#getDependentLocality()}.
*
* @param dependentLocality the dependent locality name, or null to clear an existing value.
*/
@CanIgnoreReturnValue
public Builder setDependentLocality(String dependentLocality) {
return set(AddressField.DEPENDENT_LOCALITY, dependentLocality);
}
Expand All @@ -640,6 +644,7 @@ public Builder setDependentLocality(String dependentLocality) {
*
* @param postalCode the postal code, or null to clear an existing value.
*/
@CanIgnoreReturnValue
public Builder setPostalCode(String postalCode) {
return set(AddressField.POSTAL_CODE, postalCode);
}
Expand All @@ -649,6 +654,7 @@ public Builder setPostalCode(String postalCode) {
*
* @param sortingCode the sorting code, or null to clear an existing value.
*/
@CanIgnoreReturnValue
public Builder setSortingCode(String sortingCode) {
return set(AddressField.SORTING_CODE, sortingCode);
}
Expand All @@ -661,28 +667,31 @@ public Builder setSortingCode(String sortingCode) {
*
* @param languageCode the BCP-47 language code, or null to clear an existing value.
*/
@CanIgnoreReturnValue
public Builder setLanguageCode(String languageCode) {
this.language = languageCode;
return this;
}

/**
* Sets multiple unstructured street level lines in the address. Calling this method will
* always discard any existing address lines before adding new ones.
* <p>
* Note that the number of lines set by this method is preserved in the builder's state but a
* Sets multiple unstructured street level lines in the address. Calling this method will always
* discard any existing address lines before adding new ones.
*
* <p>Note that the number of lines set by this method is preserved in the builder's state but a
* single line set here may result in multiple lines in the resulting {@code AddressData}
* instance if it contains embedded newline characters.
* <p>
* For example:
*
* <p>For example:
*
* <pre>{@code
* data = AddressData.builder()
* .setAddressLines(Arrays.asList("First line\nSecond line"))
* .setAddressLine2("Last line");
* .build();
* // data.getAddressLines() == [ "First line", "Second line", "Last line" ]
* data = AddressData.builder()
* .setAddressLines(Arrays.asList("First line\nSecond line"))
* .setAddressLine2("Last line");
* .build();
* // data.getAddressLines() == [ "First line", "Second line", "Last line" ]
* }</pre>
*/
@CanIgnoreReturnValue
public Builder setAddressLines(Iterable<String> lines) {
addressLines.clear();
for (String line : lines) {
Expand All @@ -691,29 +700,30 @@ public Builder setAddressLines(Iterable<String> lines) {
return this;
}

/**
* Adds another address line. Embedded newlines will be normalized when "build()" is called.
*/
/** Adds another address line. Embedded newlines will be normalized when "build()" is called. */
// TODO: Consider removing this method if nobody is using it to simplify the API.
@CanIgnoreReturnValue
public Builder addAddressLine(String value) {
addressLines.add(value);
return this;
}

/**
* Sets multiple street lines from a single street string, clearing any existing address lines
* first. The input string may contain new lines which will result in multiple separate lines
* in the resulting {@code AddressData} instance. After splitting, each line is trimmed and
* empty lines are ignored.
* <p>
* Example: {@code " \n \n1600 Amphitheatre Ave\n\nRoom 122"} will set the lines:
* first. The input string may contain new lines which will result in multiple separate lines in
* the resulting {@code AddressData} instance. After splitting, each line is trimmed and empty
* lines are ignored.
*
* <p>Example: {@code " \n \n1600 Amphitheatre Ave\n\nRoom 122"} will set the lines:
*
* <ol>
* <li>"1600 Amphitheatre Ave"
* <li>"Room 122"
* <li>"1600 Amphitheatre Ave"
* <li>"Room 122"
* </ol>
*
* @param value a string containing one or more address lines, separated by {@code "\n"}.
*/
@CanIgnoreReturnValue
public Builder setAddress(String value) {
addressLines.clear();
addressLines.add(value);
Expand All @@ -725,6 +735,7 @@ public Builder setAddress(String value) {
* Copies all the data of the given address into the builder. Any existing data in the builder
* is discarded.
*/
@CanIgnoreReturnValue
public Builder set(AddressData data) {
fields.clear();
for (AddressField addressField : SINGLE_VALUE_FIELDS) {
Expand All @@ -742,6 +753,7 @@ public Builder set(AddressData data) {
* @deprecated Use {@link #setAddressLines} instead.
*/
@Deprecated
@CanIgnoreReturnValue
public Builder setAddressLine1(String value) {
return setAddressLine(1, value);
}
Expand All @@ -752,6 +764,7 @@ public Builder setAddressLine1(String value) {
* @deprecated Use {@link #setAddressLines} instead.
*/
@Deprecated
@CanIgnoreReturnValue
public Builder setAddressLine2(String value) {
return setAddressLine(2, value);
}
Expand All @@ -761,6 +774,7 @@ public Builder setAddressLine2(String value) {
*
* @param organization the organization, or null to clear an existing value.
*/
@CanIgnoreReturnValue
public Builder setOrganization(String organization) {
return set(AddressField.ORGANIZATION, organization);
}
Expand All @@ -770,6 +784,7 @@ public Builder setOrganization(String organization) {
*
* @param recipient the recipient, or null to clear an existing value.
*/
@CanIgnoreReturnValue
public Builder setRecipient(String recipient) {
return set(AddressField.RECIPIENT, recipient);
}
Expand All @@ -792,6 +807,7 @@ public Builder setLandmarkAddressDescriptor(String landmarkAddressDescriptor) {
*
* @param landmarkAffix the landmark affix, or null to clear an existing value.
*/
@CanIgnoreReturnValue
public Builder setLandmarkAffix(String landmarkAffix) {
return set(AddressField.LANDMARK_AFFIX, landmarkAffix);
}
Expand All @@ -801,6 +817,7 @@ public Builder setLandmarkAffix(String landmarkAffix) {
*
* @param landmarkName the landmark name, or null to clear an existing value.
*/
@CanIgnoreReturnValue
public Builder setLandmarkName(String landmarkName) {
return set(AddressField.LANDMARK_NAME, landmarkName);
}
Expand All @@ -813,6 +830,7 @@ public Builder setLandmarkName(String landmarkName) {
*/
@Deprecated
@SuppressWarnings("deprecation")
@CanIgnoreReturnValue
// TODO: Reimplement using public API as a utility function in AddressWidget (the only caller).
public Builder set(AddressField field, String value) {
if (SINGLE_VALUE_FIELDS.contains(field)) {
Expand All @@ -839,6 +857,7 @@ public Builder set(AddressField field, String value) {

// This may preserve whitespace at the ends of lines, but this gets normalized when we build
// the data instance.
@CanIgnoreReturnValue
private Builder setAddressLine(int lineNum, String value) {
if (Util.trimToNull(value) == null) {
if (lineNum < addressLines.size()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,7 @@ char getChar() {
* field, in the UI.
*/
// TODO: We'd probably be better off just having a widthType field in the enum.
private WidthType getDefaultWidthType() {
WidthType getDefaultWidthType() {
return this.equals(POSTAL_CODE) || this.equals(SORTING_CODE) ? WidthType.SHORT : WidthType.LONG;
}

/**
* Returns default width of this address field. Takes per-country heuristics into account for
* text input fields. This may be overridden for a specific country when we have data for the
* possible inputs in that field and use a drop-down, rather than a text field, in the UI.
*/
public WidthType getWidthTypeForRegion(String regionCode) {
Util.checkNotNull(regionCode);
WidthType width = FormatInterpreter.getWidthOverride(this, regionCode);
return width != null ? width : getDefaultWidthType();
}
}
Loading