// Path: app/src/main/java/me/itangqi/buildingblocks/domain/utils/ToastUtils.java
// public class ToastUtils {
// 
//     private ToastUtils() {
//     }
// 
//     private static void show(Context context, int resId, int duration) {
//         Toast.makeText(context, resId, duration).show();
//     }
// 
//     private static void show(Context context, String message, int duration) {
//         Toast.makeText(context, message, duration).show();
//     }
// 
//     public static void showShort(int resId) {
//         Toast.makeText(App.getContext(), resId, Toast.LENGTH_SHORT).show();
//     }
// 
//     public static void showShort(String message) {
//         Toast.makeText(App.getContext(), message, Toast.LENGTH_SHORT).show();
//     }
// 
//     public static void showLong(int resId) {
//         Toast.makeText(App.getContext(), resId, Toast.LENGTH_LONG).show();
//     }
// 
//     public static void showLong(String message) {
//         Toast.makeText(App.getContext(), message, Toast.LENGTH_LONG).show();
//     }
// }


import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.text.Spanned;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.TextView;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.PlaceBuffer;
import com.google.android.gms.location.places.PlaceLikelihoodBuffer;
import com.google.android.gms.location.places.Places;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import butterknife.Bind;
import butterknife.ButterKnife;
import me.imid.swipebacklayout.lib.SwipeBackLayout;
import me.itangqi.buildingblocks.R;
import me.itangqi.buildingblocks.domain.application.App;
import me.itangqi.buildingblocks.domain.utils.ToastUtils;
import me.itangqi.buildingblocks.view.adapter.GooglePlacesAdapter;
import me.itangqi.buildingblocks.view.ui.activity.base.SwipeBackActivity;
            // Display the third party attributions if set.
            final CharSequence thirdPartyAttribution = places.getAttributions();
            if (thirdPartyAttribution == null) {
                mPlaceDetailsAttribution.setVisibility(View.GONE);
            } else {
                mPlaceDetailsAttribution.setVisibility(View.VISIBLE);
                mPlaceDetailsAttribution.setText(Html.fromHtml(thirdPartyAttribution.toString()));
            }

            places.release();
        }
    };

    private static Spanned formatPlaceDetails(Resources res, CharSequence name, String id,
                                              CharSequence address, CharSequence phoneNumber, Uri websiteUri) {
        return Html.fromHtml(res.getString(R.string.place_details, name, id, address, phoneNumber,
                websiteUri));
    }

    /**
     * Called when the Activity could not connect to Google Play services and the auto manager
     * could resolve the error automatically.
     * In this case the API is not available and notify the user.
     *
     * @param connectionResult can be inspected to determine the cause of the failure
     */
    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {

        // TODO(Developer): Check error code and notify the user of error state and resolution.
// Path: app/src/main/java/me/itangqi/buildingblocks/domain/utils/ToastUtils.java
// public class ToastUtils {
// 
//     private ToastUtils() {
//     }
// 
//     private static void show(Context context, int resId, int duration) {
//         Toast.makeText(context, resId, duration).show();
//     }
// 
//     private static void show(Context context, String message, int duration) {
//         Toast.makeText(context, message, duration).show();
//     }
// 
//     public static void showShort(int resId) {
//         Toast.makeText(App.getContext(), resId, Toast.LENGTH_SHORT).show();
//     }
// 
//     public static void showShort(String message) {
//         Toast.makeText(App.getContext(), message, Toast.LENGTH_SHORT).show();
//     }
// 
//     public static void showLong(int resId) {
//         Toast.makeText(App.getContext(), resId, Toast.LENGTH_LONG).show();
//     }
// 
//     public static void showLong(String message) {
//         Toast.makeText(App.getContext(), message, Toast.LENGTH_LONG).show();
//     }
// }


// Path: app/src/main/java/me/itangqi/buildingblocks/view/ui/activity/GooglePlacesActivity.java
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.text.Spanned;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.TextView;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.PlaceBuffer;
import com.google.android.gms.location.places.PlaceLikelihoodBuffer;
import com.google.android.gms.location.places.Places;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import butterknife.Bind;
import butterknife.ButterKnife;
import me.imid.swipebacklayout.lib.SwipeBackLayout;
import me.itangqi.buildingblocks.R;
import me.itangqi.buildingblocks.domain.application.App;
import me.itangqi.buildingblocks.domain.utils.ToastUtils;
import me.itangqi.buildingblocks.view.adapter.GooglePlacesAdapter;
import me.itangqi.buildingblocks.view.ui.activity.base.SwipeBackActivity;

            // Display the third party attributions if set.
            final CharSequence thirdPartyAttribution = places.getAttributions();
            if (thirdPartyAttribution == null) {
                mPlaceDetailsAttribution.setVisibility(View.GONE);
            } else {
                mPlaceDetailsAttribution.setVisibility(View.VISIBLE);
                mPlaceDetailsAttribution.setText(Html.fromHtml(thirdPartyAttribution.toString()));
            }

            places.release();
        }
    };

    private static Spanned formatPlaceDetails(Resources res, CharSequence name, String id,
                                              CharSequence address, CharSequence phoneNumber, Uri websiteUri) {
        return Html.fromHtml(res.getString(R.string.place_details, name, id, address, phoneNumber,
                websiteUri));
    }

    /**
     * Called when the Activity could not connect to Google Play services and the auto manager
     * could resolve the error automatically.
     * In this case the API is not available and notify the user.
     *
     * @param connectionResult can be inspected to determine the cause of the failure
     */
    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {

        // TODO(Developer): Check error code and notify the user of error state and resolution.
        ToastUtils.showShort("Could not connect to Google API Client: Error " + connectionResult.getErrorCode());