This post is still a work-in-progress.

Table Of Contents

  • Google Maps
  • Common Intent
  • Create Menu on Action Bar
  • Working with strings.xml
  • Create Scroll List
  • Create a URI
  • UI
  • Data Binding

UI

  • FrameLayout: Used to display only one item
  • RelativeLayout: Enables you to decide the relation between the different views. i.e, The textbox should be left to the ImageView…
  • ConstraintLayout: uses constraints to place views – efficient instead of using recursive layouts. notice the layout_constraintLeft_...

 

Data Binding

Enable Data Binding in your application

in the module build.gradle file, under the Android tag, enable the binding as follows:

android {
    ...
    dataBinding.enabled = true;
}

Use <layout> as the root element of the layout activity

in our example, it is main_activity.xml. Don’t forget to move the xmlns attributes to the root element:

<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">

Create a data binding instance called mBinding of type ActivityMainBinding at​​​  MainActivity.java (this could be any java file)

ActivityMainBinding mBinding;

Set the Content View using DataBindingUtil to the activity_main layout

DataBindUtil.setContentView replaces our normal call of setContent view.
DataBindingUtil also created our ActivityMainBinding that we will eventually use to
display all of our data.

 mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);

Load a BoardingPassInfo object with fake data using FakeDataUtils

BoardingPassInfo fakeBoardingInfo = FakeDataUtils.generateFakeBoardingPassInfo();

Call displayBoardingPassInfo and pass the fake BoardingInfo instance

displayBoardingPassInfo(fakeBoardingInfo);
    private void displayBoardingPassInfo(BoardingPassInfo info) {

        // COMPLETED (6) Use mBinding to set the Text in all the textViews using the data in info
        mBinding.textViewPassengerName.setText(info.passengerName);
        mBinding.textViewOriginAirport.setText(info.originCode);
        mBinding.textViewFlightCode.setText(info.flightCode);
        mBinding.textViewDestinationAirport.setText(info.destCode);

Activity LifeCycle

lifecycle

Google Maps

Ref here

Common Intents

Common intent is used to share data with other apps via a url.

private void showMap(Uri geoLocation) {
    /*
     * Again, we create an Intent with the action, ACTION_VIEW because we want to VIEW the
     * contents of this Uri.
     */
    Intent intent = new Intent(Intent.ACTION_VIEW);

    /*
     * Using setData to set the Uri of this Intent has the exact same affect as passing it in
     * the Intent's constructor. This is simply an alternate way of doing this.
     */
    intent.setData(geoLocation);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}

Ref here

 

Create Menu on Action Bar

1. Right click the resource directory(res) -> New -> Android Resource Directory

Capture

2. In the resource drop list, select menu

Capture2

3. Right-click the generated menu folder under res, and then New->Menu Resource File

4. Fill Menu with items

<item
    android:id="@+id/action_search"
    android:orderInCategory="1"
    app:showAsAction="ifRoom"
    android:title="@string/search"/>

5. Override menu methods: In the activity java file, override the next methods:

6. Toast: On line 7, use the toast to get the next feature:

toast

Working with strings.xml

you can get a String saved in res -> values -> strings.xml by calling the getString method.

String myString = getString(R.string.today);

 

Create Scroll List

add the next to the activity layout xml:

then fill the list as follows:

Create a URI

To create a well-formed Uri without having to worry about the particular uri components, use the Uri Builder