W3w-android-components - An Android library to use what3words autosuggest

Overview

what3words w3w-android-components

An Android library to use the what3words v3 API autosuggest.

alt textalt textalt text

To obtain an API key, please visit https://what3words.com/select-plan and sign up for an account.

Installation

The artifact is available through Maven Central

Android minumum SDK support

Generic badge

Gradle

implementation 'com.what3words:w3w-android-components:2.1.0'

Documentation

See the what3words public API documentation

Usage

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.yourpackage.yourapp">

    <uses-permission android:name="android.permission.INTERNET" />
    ...

add this to build.gradle (app level)

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

add this the following proguard rules

-keep class com.what3words.javawrapper.request.* { *; }
-keep class com.what3words.javawrapper.response.* { *; }

activity_main.xml

<androidx.constraintlayout.widget.ConstraintLayout
	  xmlns:android="http://schemas.android.com/apk/res/android"
	  xmlns:app="http://schemas.android.com/apk/res-auto"
	  android:layout_width="match_parent"
	  android:layout_height="match_parent">

	 <com.what3words.components.text.W3WAutoSuggestEditText
		  android:id="@+id/suggestionEditText"
		  android:layout_width="0dp"
		  android:layout_height="wrap_content"
		  app:layout_constraintEnd_toEndOf="parent"
		  app:layout_constraintStart_toStartOf="parent"
		  app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Kotlin

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

	suggestionEditText.apiKey("YOUR_API_KEY_HERE")
            .returnCoordinates(false)
            .onSelected { w3wSuggestion ->
                if (w3wSuggestion != null) {
                    Log.i( "MainActivity","words: ${w3wSuggestion.suggestion.words}, country: ${w3wSuggestion.suggestion.country}, distance: ${w3wSuggestion.suggestion.distanceToFocusKm}, near: ${w3wSuggestion.suggestion.nearestPlace}, latitude: ${w3wSuggestion.coordinates?.lat}, longitude: ${w3wSuggestion.coordinates?.lng}")
                } else {
                    Log.i("MainActivity", "invalid w3w address")
                }
            }
            .onError {
                Log.e("MainActivity", "${it.key} - ${it.message}")
            }
}

Java

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        W3WAutoSuggestEditText autoSuggestEditText = findViewById(R.id.suggestionEditText);
        autoSuggestEditText.apiKey("YOUR_API_KEY_HERE")
                .returnCoordinates(false)
                .onSelected(null, null, (W3WSuggestion w3wSuggestion) -> {
                    if (w3wSuggestion != null) {
                        Log.i("MainActivity", String.format("words: %s, country: %s, near: %s", w3wSuggestion.getSuggestion().getWords(), w3wSuggestion.getSuggestion().getCountry(), w3wSuggestion.getSuggestion().getNearestPlace()));
                    } else {
                        Log.i("MainActivity", "invalid w3w address");
                    }
                })
                .onError(null, (APIResponse.What3WordsError what3WordsError) -> Log.e("MainActivity", String.format("%s - %s", what3WordsError.getKey(), what3WordsError.getMessage())));
    }

If you run our Enterprise Suite API Server yourself, you may specify the URL to your own server like so:

 suggestionEditText.apiKey("YOUR_API_KEY_HERE", "https://api.yourserver.com")

General properties:

property default value type description XML Programatically
apiKey N/A String Your what3words API key. mandatory ✔️
hint e.g. lock.spout.radar String Placeholder text to display in the input in its default empty state. ✔️
errorMessage An error occurred. Please try again later String Overwrite the generic error message with a custom value. ✔️ ✔️
invalidAddressMessage No valid what3words address found String Overwrite the validation error message with a custom value. ✔️ ✔️
focus N/A Coordinates This is a location, specified as a latitude/longitude (often where the user making the query is). If specified, the results will be weighted to give preference to those near the focus ✔️
clipToCountry N/A String Clip results to a given country or comma separated list of countries. Example value:"GB,US". ✔️
clipToCircle N/A Coordinates, Int Clip results to a circle, specified by Coordinate(lat,lng) and kilometres, where kilometres in the radius of the circle. ✔️
clipToBoundingBox N/A BoundingBox Clip results to a bounding box specified using co-ordinates. ✔️
clipToPolygon N/A List of Coordinates Clip results to a bounding box specified using co-ordinates. ✔️
returnCoordinates false Boolean Calls the what3words API to obtain the coordinates for the selected 3 word address (to then use on a map or pass through to a logistic company etc) ✔️ ✔️
allowInvalid3wa false Boolean Allow invalid 3 word address ✔️
suggestionsListPosition BELOW Enum Suggestion list position which can be below (default) the EditText or above ✔️ ✔️

Enable voice autosuggest:

alt textalt textalt text

The component also allows for voice input using the what3words Voice API. This feature allows the user to say 3 words and using speech recognition technology displays 3 word address suggestions to the user.

Before enabling Voice AutoSuggest you will need to add a Voice API plan in your account.

By default the voice language is set to English but this can be changed using the voiceLanguage property (for list of available languages please check the properties table below). Voice input respects the clipping and focus options applied within the general properties. We recommend applying clipping and focus where possible to display as accurate suggestions as possible. To enable voice you can do with programmatically or directly in the XML.

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.yourpackage.yourapp">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    ...

add following proguard rules

-keep class com.what3words.androidwrapper.voice.* { *; } //only needed if using voice functionality.

activity_main.xml

 <com.what3words.components.text.W3WAutoSuggestEditText
		  android:id="@+id/suggestionEditText"
		  android:layout_width="0dp"
		  android:layout_height="wrap_content"
		  app:layout_constraintEnd_toEndOf="parent"
		  app:layout_constraintStart_toStartOf="parent"
		  app:layout_constraintTop_toTopOf="parent"
		  app:voiceEnabled="true" />

or

 suggestionEditText.apiKey("YOUR_API_KEY_HERE")
	        .returnCoordinates(false)
	        .voiceEnabled(true)
		...

Voice properties:

property default value type description XML Programatically
voiceEnabled false Boolean Enables voice suggestion to allow the user to say the three word address instead of writing it. ✔️ ✔️
voiceFullscreen false Boolean Voice activation will be fullscreen instead of inline. ✔️ ✔️
voiceLanguage en String Available voice languages: ar for Arabic, cmn for Mandarin Chinese, de for German, en Global English (default), es for Spanish, hi for Hindi, ja for Japanese and ko for Korean ✔️ ✔️

Voice only:

If you want to use voice-only (no text input) please look at our voice-sample app in this repo for examples of how to use our W3WAutoSuggestVoice component.

Advanced usage:

If you want to check different ways to use our component please look at our advanced-sample app in this repo for examples of how to use and customize our W3WAutoSuggestText component.

alt text

Styles:

Use our base style as parent and you can set the custom properties available with XML on the table above and the normal EditText styling, i.e:

<style name="YourCustomStyle" parent="Widget.AppCompat.W3WAutoSuggestEditText">
    <item name="android:textColor">#000000</item>
    <item name="android:textColorHint">#888888</item>
    <item name="invalidAddressMessage">Your custom invalid address message</item>
    <item name="errorMessage">Your custom error message</item>
    <item name="android:hint">Your custom placeholder</item>
    <item name="android:textAppearance">@style/YourCustomStyleTextAppearance</item>
</style>

<style name="YourCustomStyleTextAppearance" parent="TextAppearance.AppCompat">
    <item name="android:textSize">22sp</item>
    <item name="android:fontFamily">sans-serif-medium</item>
</style>

alt textalt textalt text

Full documentation:

Existing components:

Name Summary
W3WAutoSuggestEditText class W3WAutoSuggestEditText : AppCompatEditText
A AppCompatEditText to simplify the integration of what3words text and voice auto-suggest API in your app.
W3WAutoSuggestVoice class W3WAutoSuggestVoice : ConstraintLayout
A View to simplify the integration of what3words voice auto-suggest API in your app.
W3WAutoSuggestErrorMessage class W3WAutoSuggestErrorMessage : AppCompatTextView
A AppCompatTextView styled and ready to show error messages.
W3WAutoSuggestPicker class W3WAutoSuggestPicker : RecyclerView
A RecyclerView to show W3WSuggestion returned by w3w auto suggest component modularized to allow developers to choose picker location on the screen.
Comments
  • Refactor component, new features and improve documentation

    Refactor component, new features and improve documentation

    new w3w-android-components version 3.0.0 is available for testing, this is a major release including the following features: new microphone icon for voice. https://what3words.atlassian.net/browse/TT-7044 day/night mode support. https://what3words.atlassian.net/browse/TT-7087 improved right-to-left support. https://what3words.atlassian.net/browse/TT-7088 new loading voice animation (gives user better feedback while socket handshake is happening in the background). https://what3words.atlassian.net/browse/TT-7045 add delete text icon ("X") when text view is focused. https://what3words.atlassian.net/browse/TT-6990 big technical debt refactor, using the latest features added on java and android wrappers, reducing code duplication. https://what3words.atlassian.net/browse/TT-6879, https://what3words.atlassian.net/browse/TT-6881 new support for SDK integration for text search, creating a hybrid using SDK for text (offline support) and Voice API for voice (online only), support offline voice will be in the next version. https://what3words.atlassian.net/browse/TT-3660 new voice listening animations added inline, popup animation, and fullscreen. improved general performance and code readability. major and minor bug fixes. all generated by the new CircleCI pipeline, added unit tests, and SonarCloud support.

    opened by mani-w3w 3
  • Mt 478 w3wAutoSuggestTextField w3w sdk support

    Mt 478 w3wAutoSuggestTextField w3w sdk support

    • Fixed W3WAutoSuggestTextField custom style bug
    • Renamed W3WAutoSuggestTextFieldState.internalW3WAutoSuggestEditText
    • Created README.md (WIP) file for compose wrapper Prosper 3 minutes ago
    opened by prosper-w3w 2
  • W3WAutoSuggestTextField sdk support

    W3WAutoSuggestTextField sdk support

    • Provided client access to internal W3WAutoSuggestEditText
    • Refactored W3WAutoSuggestTextField to support what3words Android SDK
    • Enabled direct support for clipping filters on W3WAutoSuggestTextFieldState
    • Provided fluent interface for W3WAutoSuggestTextFieldState
    • Added onHomeClick and onDisplaySuggestions support in W3WAutoSuggestTextField
    opened by prosper-w3w 2
  • Mt 475 migrate all sub projects in what 3 words android component to use the gradle version catalog

    Mt 475 migrate all sub projects in what 3 words android component to use the gradle version catalog

    • Created version catalogs for libraries and test-libraries dependencies
    • Migrated compose-sample module to use Gradle version catalog
    • Migrated testing module to use Gradle version catalog
    opened by prosper-w3w 2
  • Mt 475 migrate all sub projects in what 3 words android component to use the gradle version catalog

    Mt 475 migrate all sub projects in what 3 words android component to use the gradle version catalog

    • Created version catalogs for libraries and test-libraries dependencies
    • Migrated compose-sample module to use Gradle version catalog
    • Enabled IDE autocompletion feature for version catalog type-safe accessors
    opened by prosper-w3w 2
  • 3.1.1

    3.1.1

    • Added support for Jetpack Compose.
    • New Jetpack Compose Sample app.
    • New voice UI flow for modal and full screen.
    • Fix UI issues.
    • Using Gradle catalog for dependency handling.
    opened by mani-w3w 1
  • Mt 455 create jetpack compose only screen that matches up with the autosuggest sample view screen using our w 3 w auto suggest text field as compose subtitle for w 3 w auto suggest edit text

    Mt 455 create jetpack compose only screen that matches up with the autosuggest sample view screen using our w 3 w auto suggest text field as compose subtitle for w 3 w auto suggest edit text

    • Added support for specifying AutoSuggestEditText hint
    • Added support for specifying AutoSuggest Voice Language
    • Completed AutoSuggest Compose sample app
    opened by prosper-w3w 1
  • Mt 455 created jetpack compose only screen that matches up with the autosuggest sample screen

    Mt 455 created jetpack compose only screen that matches up with the autosuggest sample screen

    Created a Jetpack Compose-only screen that matches up with the autosuggest sample (xml/view) screen using our W3WAutoSuggestTextField as a Jetpack Compose's subtitle for the W3WAutoSuggestEditText.

    opened by prosper-w3w 1
  • map-component changes

    map-component changes

    • added display functionality to allow map-component to set a selected suggestion on the W3WAutosuggestEditText.
    • updated android-wrapper dependency to 3.1.18.
    opened by mani-w3w 1
  • Mt 309 circle ci run UI tests local machine

    Mt 309 circle ci run UI tests local machine

    I modified Circleci's config.yml to ensure that Local UI tests are run at every commit as we do normally with Unit tests by creating a new job to run UI tests on an emulator on Circleci.

    I also adjusted the sonarqube.gradle file to merge the coverage reports from the lib and testing module, then send the merged report to the SonarCloud project for what3words-android-components. At the time of submitting this PR, the code coverage percentage on our android component has increased from 4% to 12.5%, with the testing module achieving a code coverage of 60%, then the lib module has coverage of 4%. I also excluded the remaining sample apps modules from the code coverage report.

    opened by prosper-w3w 1
  • Integrated android test orchestrator to improve test stability

    Integrated android test orchestrator to improve test stability

    Integrated android test orchestrator to improve test stability and made autosuggest component to utilize pre-production URL, and overall test refactor

    opened by prosper-w3w 1
Releases(3.1.1)
  • 3.1.1(Dec 13, 2022)

    What's new:

    • Added support for Jetpack Compose

    • New Jetpack Compose Sample app, to help our partners on how to use our android components when using Jetpack Compose.

    • New voice UI/UX flow for pop-up and full-screen listening modes.

    • Fix UI issues.

    • Using Gradle catalog for dependency handling.

    Source code(tar.gz)
    Source code(zip)
  • 3.1.0(Aug 17, 2022)

  • 3.0.2(Jun 28, 2022)

  • 3.0.1(May 18, 2022)

    • Allow custom voice API URLs, this will allow to test the component against dev/pre-prod voice API.
    • allowSearchFlow functionality, this was thought after Mahindra's automotive work, the reason is that if the keyboard is full screen (i.e most android phones in landscape mode) you aren't able to see suggestions meaning that for our component to work correctly in landscape it needs a search flow instead of the default autosuggest flow.
    • UI Tests for our text component Tests for all user journeys for our component.
    • Bug fixing and general improvements.
    • Added missing autosuggest filter preferLand.
    Source code(tar.gz)
    Source code(zip)
  • 3.0.0(Feb 15, 2022)

    • new microphone icon for voice.
    • day/night mode support.
    • improved right-to-left support.
    • new loading voice animation (gives user better feedback while socket handshake is happening in the background).
    • add delete text icon ("X") when text view is focused.
    • big technical debt refactor, using the latest features added on java and android wrappers, reducing code duplication.
    • new support for SDK integration for text search, creating a hybrid using SDK for text (offline support) and Voice API for voice (online only), support offline voice will be in the next version.
    • new voice listening animations added inline, popup animation, and fullscreen.
    • improved general performance and code readability.
    • major and minor bug fixes.
    Source code(tar.gz)
    Source code(zip)
  • 2.1.0(Jun 24, 2021)

    • removed flags ✔️
    • added distance and layout changes to suggestion list item ✔️
    • fixed issue with tick image not showing at all times✔️
    • fixed issue with wrong positioning of child views (list of suggestion, error message, did you mean, etc.) if our W3WAutoSuggestEditText starts as visibility = GONE ✔️
    • changed /// image to text ✔️
    Source code(tar.gz)
    Source code(zip)
  • 2.0.2(Feb 18, 2021)

    • Added new functionality to W3WAutoSuggestVoice: start(), stop(), onListeningStateChanged()
    • Updated dependencies including wrapper with voice api bug fixes.
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0(Feb 1, 2021)

    this release includes:

    • name changed from w3w-autosuggest-edittext-android to w3w-android-components, across github, maven and lib namespace.
    • Did you mean feature added
    • Copy-paste w3w URLs included encoded ones
    • Allow invalid 3wa free-text disabled by default)

    https://search.maven.org/artifact/com.what3words/w3w-android-components/2.0.0/aar

    Source code(tar.gz)
    Source code(zip)
Owner
what3words
addressing the world
what3words
AbstractMvp 0.8 0.0 Kotlin is a library that provides abstract components for MVP architecture realization, with problems solutions that are exist in classic MVP.

MinSDK 14+ AbstractMvp AbstractMvp is a library that provides abstract components for MVP architecture realization, with problems solutions that are e

Robert 12 Apr 5, 2022
A Gradle plugin to easily publish library components to Maven.

Component Publisher A Gradle plugin to easily publish components based on maven-publish. You can find the latest released plugin on Gradle Plugin Port

Hulk Su 7 Oct 24, 2022
This Project for how to use MVVM , state flow, Retrofit, dagger hit, coroutine , use cases with Clean architecture.

Clean-architecture This Project for how to use MVVM , state flow, Retrofit, dagger hit, coroutine , use cases with Clean architecture. Why i should us

Kareem Aboelatta 10 Dec 13, 2022
LifecycleMvp 1.2 0.0 Kotlin is MVP architecture implementation with Android Architecture Components and Kotlin language features

MinSDK 14+ Download Gradle Add to project level build.gradle allprojects { repositories { ... maven { url 'https://jitpack.io' }

Robert 20 Nov 9, 2021
A fork of our clean architecture boilerplate, this time using the Android Architecture Components

Android Clean Architecture Components Boilerplate Note: This is a fork of our original Clean Architecture Boilerplate, except in this repo we have swi

Buffer 1.3k Jan 3, 2023
📚 Sample Android Components Architecture on a modular word focused on the scalability, testability and maintainability written in Kotlin, following best practices using Jetpack.

Android Components Architecture in a Modular Word Android Components Architecture in a Modular Word is a sample project that presents modern, 2020 app

Madalin Valceleanu 2.3k Jan 4, 2023
Multi module architecture Android template project using MVVM, Dagger-Hilt, and Navigation Components

ModularAppTemplate An Android template project following a multi module approach with clean architecture. It has been built following Clean Architectu

Mbuodile Obiosio 7 May 23, 2022
Example Multi module architecture Android project using MVVM, Dynamic Features, Dagger-Hilt, Coroutines and Navigation Components

ModularDynamicFeatureHilt An Android template project following a multi module approach with clean architecture. It has been built following Clean Arc

Mbuodile Obiosio 25 Nov 23, 2022
Built with Jetpack compose, multi modules MVVM clean architecture, coroutines + flow, dependency injection, jetpack navigation and other jetpack components

RickAndMortyCompose - Work in progress A simple app using Jetpack compose, clean architecture, multi modules, coroutines + flows, dependency injection

Daniel Waiguru 9 Jul 13, 2022
Kotlin Multiplatform lifecycle-aware business logic components (aka BLoCs) with routing functionality and pluggable UI (Jetpack Compose, SwiftUI, JS React, etc.), inspired by Badoos RIBs fork of the Uber RIBs framework

Decompose Please see the project website for documentation and APIs. Decompose is a Kotlin Multiplatform library for breaking down your code into life

Arkadii Ivanov 819 Dec 29, 2022
A minimal notes application in Jetpack Compose with MVVM architecture. Built with components like DataStore, Coroutines, ViewModel, LiveData, Room, Navigation-Compose, Coil, koin etc.

Paper - A Minimal Notes App A minimal notes application in Jetpack Compose with MVVM architecture. Built with components like DataStore, Coroutines, V

Akshay Sharma 139 Jan 2, 2023
To illustrate the clean architecture and modularisation with other components.

CleanNews A news app that provides data from mediastack API using clean architecture, kotlin coroutines, architectural pattern (MVI) with Mavericks. .

Yves Kalume 4 Feb 13, 2022
Android calendar library provides easy to use widget with events

Kotlin-AgendaCalendarView Kotlin-AgendaCalendarView based on AgendaCalendarView Kotlin-AgendaCalendarView is a awesome calendar widget with a list of

Ognev Zair 88 Nov 21, 2022
Android Spinner Dialog Library supported on both Java and Kotlin, Use for single or multi selection of choice

SpinnerDialog Android Spinner Dialog Library, Use for single or multi selection of choice Android UI Download To include SpinnerDialog in your project

Hamza Khan 55 Sep 15, 2022
This is a sample app to use [Molecule library] and solve some scoping problems in Android development.

Android sample app Problem It's started when P.Y. in Twitter shared this tweet and his post, which is a correct complain about introducing a new set o

Hadi 37 Oct 28, 2022
Library to use Kotlin Coroutines from Swift code in KMP apps

KMP-NativeCoroutines A library to use Kotlin Coroutines from Swift code in KMP apps. Flows Kotlin Create an extension property to expose the Flow as a

Rick Clephas 508 Jan 3, 2023
Kotlin parser library with an easy-to-use DSL

Pratt Library for parsing expressions and a beautiful Kotlin DSL Just define your operators and operands with the Kotlin DSL and the parser is ready!

furetur 9 Oct 17, 2022
A library with many useful and easy-to-use features

This library was made as a replacement for qLib and in the future cubed. These 2 plugins are hard to get you hands on and one of them has many outdated methods so this is a more modern version of those things

Max 1 May 6, 2022
A Kotlin library providing a simple, high-performance way to use off-heap native memory in JVM applications.

native_memory_allocator A library which uses sun.misc.Unsafe to allocate off-heap native memory. Motivation The goal of this project is to provide a s

Target 5 Dec 8, 2022