Skip to content

Latest commit

 

History

History
 
 

Crane

Crane sample

Crane is a travel app part of the Material Studies built with Jetpack Compose. The goal of the sample is to showcase Material components, draggable UI elements, Android Views inside Compose, and UI state handling.

To try out this sample app, you need to use the latest Canary version of Android Studio 4.2. You can clone this repository or import the project from Android Studio following the steps here.

Screenshots

Features

This sample contains 4 screens:

  • Landing screen that fades out after 2 seconds then slides the main content in from the bottom of the screen.
  • Home screen where you can explore flights, hotels, and restaurants specifying the number of people.
  • Clicking on the number of people refreshes the destinations.
  • The backdrop is draggable and can pin to the top of the screen, just under the search criteria, and to the bottom. Implemented here.
  • Destination's images are retrieved using the coil-accompanist library.
  • Calendar screen. Tapping on Select Dates takes you to a calendar built completely from scratch. It makes a heavy usage of Compose's state APIs.
  • Destination's Details screen. When tapping on a destination, a new screen implemented using a different Activity will be displayed. In there, you can see the a MapView embedded in Compose and Compose buttons updating the Android View. Notice how you can also interact with the MapView seamlessly.

Google Maps SDK

To get the MapView working, you need to get an API key as the documentation says, and include it in the local.properties file as follows:

google.maps.key={insert_your_api_key_here}

Data

The data is hardcoded in the CraneData file and exposed to the UI using the MainViewModel. Image resources are retrieved from Unsplash.

Testing

Crane has Compose-only tests (e.g. HomeTest) but also tests covering Compose and the view-based system (e.g. DetailsActivityTest). The latter uses the onActivity method of the ActivityScenarioRule to access information from the MapView.

License

Copyright 2020 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
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.