com.google.android.gms.location.places.ui.PlacePicker Java Examples

The following examples show how to use com.google.android.gms.location.places.ui.PlacePicker. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChatActivity.java    From NaviBee with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onModalOptionSelected(@Nullable String s, @NotNull Option option) {
    switch (option.getId()) {
        case SEND_PHOTO:
            PickImageDialog.build(new PickSetup().setSystemDialog(true)).show(ChatActivity.this);
            break;
        case SEND_LOCATION:
            try {
                PlacePicker.IntentBuilder builder1 = new PlacePicker.IntentBuilder();
                startActivityForResult(builder1.build(ChatActivity.this), PLACE_PICKER_REQUEST);
            } catch (Exception e) {
                Timber.e(e, "send location error.");
            }
            break;
        case SEND_VOICE_CALL:
            String voiceCallChannelId = UUID.randomUUID().toString();
            conversation.sendMessage("voicecall", voiceCallChannelId);
            break;
        case SEND_REALTIME_LOCATION:
            Intent intent = new Intent(this, RealTimeLocationDisplayActivity.class);
            intent.putExtra(RealTimeLocationDisplayActivity.EXTRA_CONVID, conversation.getConvId());
            startActivity(intent);
            conversation.sendMessage("realtimelocation", "");
            break;
    }
}
 
Example #2
Source File: MapsActivity.java    From io2015-codelabs with Apache License 2.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_PLACE_PICKER) {
        if (resultCode == Activity.RESULT_OK) {
            Place place = PlacePicker.getPlace(data, this);

            Map<String, Object> checkoutData = new HashMap<>();
            checkoutData.put("time", ServerValue.TIMESTAMP);

            mFirebase.child(FIREBASE_ROOT_NODE).child(place.getId()).setValue(checkoutData);

        } else if (resultCode == PlacePicker.RESULT_ERROR) {
            Toast.makeText(this, "Places API failure! Check the API is enabled for your key",
                    Toast.LENGTH_LONG).show();
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
 
Example #3
Source File: ChatActivity.java    From NaviBee with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == PLACE_PICKER_REQUEST) {
        if (resultCode == RESULT_OK) {
            PlacePicker.getLatLngBounds(data);
            Place place = PlacePicker.getPlace(this, data);
            conversation.sendLocation(place.getLatLng().latitude, place.getLatLng().longitude);
        }
    }
}
 
Example #4
Source File: EventEditActivity.java    From NaviBee with GNU General Public License v3.0 5 votes vote down vote up
public void showPlacePicker(View view) {
    locationLayout.setError(null);
    try {
        PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
        startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
    } catch ( GooglePlayServicesNotAvailableException |
              GooglePlayServicesRepairableException ignored) {
    }
}
 
Example #5
Source File: EventEditActivity.java    From NaviBee with GNU General Public License v3.0 5 votes vote down vote up
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    // select friend feedback
    switch (requestCode) {
        case SELECT_FRIEND_REQUEST:
        if(resultCode == RESULT_OK) {
            selectedUsers = (HashMap<String, UserInfoManager.UserInfo>)
                    intent.getSerializableExtra("selected");
            // show chips result
            setChipGroupView(selectedUsers);
        }
        break;
        case IMAGE_REVIEW_REQUEST:
        if(resultCode == RESULT_OK) {
            Boolean isDeleted = intent.getBooleanExtra("isDeleted", false);
            int position = intent.getIntExtra("position", -1);
            if(isDeleted){
                pics.remove(position);
                picsUri.remove(position);
                picsUpdate();
            }
        }
        break;
        case PLACE_PICKER_REQUEST:
        if (resultCode == RESULT_OK) {
            Place place = PlacePicker.getPlace(this, intent);
            String placeName = getPlaceDisplayName(place);
            locationField.setText(placeName);
            eventLocation = place;
        }
        break;
    }
}
 
Example #6
Source File: ViewActivity.java    From memoir with Apache License 2.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == PLACE_PICKER_REQUEST && resultCode == RESULT_OK) {
        Place place = PlacePicker.getPlace(this, data);
        note.setLocation(place);
        refreshLayout();
    } else if (requestCode == EDIT_BODY_REQUEST && resultCode == RESULT_OK) {
        note.body = data.getStringExtra(EditActivity.NOTE_BODY_KEY);
        refreshLayout();
    }
}
 
Example #7
Source File: SearchActivity.java    From Car-Pooling with MIT License 5 votes vote down vote up
/**
 * This method is  used to get lpickup location from maps and set it to address
 * @param requestCode request code
 * @param resultCode result code
 * @param data data fetched
 */
public void onActivityResult(int requestCode,int resultCode, Intent data){
    if(requestCode == PLACE_PICKER_REQUEST)
    {
        if(resultCode==RESULT_OK){
            Place place = PlacePicker.getPlace(data, this);
             address = String.format("Pickup Location: %s", place.getAddress());
            get_place.setText(address);
            setAddress(address);

        }
    }
}
 
Example #8
Source File: LocationEditTextPreference.java    From Advanced_Android_Development with Apache License 2.0 5 votes vote down vote up
@Override
protected View onCreateView(ViewGroup parent) {
    View view = super.onCreateView(parent);
    View currentLocation = view.findViewById(R.id.current_location);
    currentLocation.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Context context = getContext();

            // Launch the Place Picker so that the user can specify their location, and then
            // return the result to SettingsActivity.
            PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();


            // We are in a view right now, not an activity. So we need to get ourselves
            // an activity that we can use to start our Place Picker intent. By using
            // SettingsActivity in this way, we can ensure the result of the Place Picker
            // intent comes to the right place for us to process it.
            Activity settingsActivity = (SettingsActivity) context;
            try {
                settingsActivity.startActivityForResult(
                        builder.build(context), SettingsActivity.PLACE_PICKER_REQUEST);

            } catch (GooglePlayServicesNotAvailableException
                    | GooglePlayServicesRepairableException e) {
                // What did you do?? This is why we check Google Play services in onResume!!!
                // The difference in these exception types is the difference between pausing
                // for a moment to prompt the user to update/install/enable Play services vs
                // complete and utter failure.
                // If you prefer to manage Google Play services dynamically, then you can do so
                // by responding to these exceptions in the right moment. But I prefer a cleaner
                // user experience, which is why you check all of this when the app resumes,
                // and then disable/enable features based on that availability.
            }
        }
    });

    return view;
}
 
Example #9
Source File: ViewActivity.java    From memoir with Apache License 2.0 4 votes vote down vote up
@OnClick(R.id.location_holder)
public void onLocationClicked() {
    final Activity activity = this;
    PopupMenu popupMenu = new PopupMenu(this, locationHolder);
    if (note.location.placeName.length() == 0) {
        popupMenu.inflate(R.menu.menu_location);
    } else {
        popupMenu.inflate(R.menu.menu_location_remove);
    }
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {

                case R.id.location_remove:
                    new AlertDialog.Builder(activity)
                            .setTitle("Remove Location")
                            .setMessage("Are you sure you want to remove the location?")
                            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    note.location.placeName = "";
                                    note.location.latitude = 0;
                                    note.location.latitude = 0;
                                    refreshLayout();
                                }
                            })
                            .setNegativeButton(android.R.string.no, null)
                            .show();
                    return true;

                case R.id.location_detect:
                    if (!isLocationEnabled()) {
                        Toast.makeText(getApplicationContext(), R.string.note_location_enable, Toast.LENGTH_SHORT).show();
                        Intent onGPS = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                        startActivity(onGPS);
                    } else if (mGoogleApiClient == null || !mGoogleApiClient.isConnected()) {
                        Toast.makeText(getApplicationContext(), R.string.location_play_error, Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(getApplicationContext(), R.string.location_wait, Toast.LENGTH_SHORT).show();
                        getCurrentLocation();
                    }
                    return true;

                case R.id.location_select:
                    backgroundTint.setVisibility(View.VISIBLE);
                    progressCircle.setVisibility(View.VISIBLE);
                    loadingText.setVisibility(View.GONE);
                    try {
                        PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
                        startActivityForResult(builder.build(activity), PLACE_PICKER_REQUEST);
                    } catch (Exception ex) {
                        Toast.makeText(getApplicationContext(), R.string.location_play_error, Toast.LENGTH_SHORT).show();
                        backgroundTint.setVisibility(View.GONE);
                        progressCircle.setVisibility(View.GONE);
                    }
                    return true;

                default:
                    return false;
            }
        }
    });
    popupMenu.show();
}
 
Example #10
Source File: SettingsActivity.java    From Advanced_Android_Development with Apache License 2.0 4 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Check to see if the result is from our Place Picker intent
    if (requestCode == PLACE_PICKER_REQUEST) {
        // Make sure the request was successful
        if (resultCode == RESULT_OK) {
            Place place = PlacePicker.getPlace(data, this);
            String address = place.getAddress().toString();
            LatLng latLong = place.getLatLng();

            // If the provided place doesn't have an address, we'll form a display-friendly
            // string from the latlng values.
            if (TextUtils.isEmpty(address)) {
                address = String.format("(%.2f, %.2f)",latLong.latitude, latLong.longitude);
            }

            SharedPreferences sharedPreferences =
                    PreferenceManager.getDefaultSharedPreferences(this);
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putString(getString(R.string.pref_location_key), address);

            // Also store the latitude and longitude so that we can use these to get a precise
            // result from our weather service. We cannot expect the weather service to
            // understand addresses that Google formats.
            editor.putFloat(getString(R.string.pref_location_latitude),
                    (float) latLong.latitude);
            editor.putFloat(getString(R.string.pref_location_longitude),
                    (float) latLong.longitude);
            editor.commit();

            // Tell the SyncAdapter that we've changed the location, so that we can update
            // our UI with new values. We need to do this manually because we are responding
            // to the PlacePicker widget result here instead of allowing the
            // LocationEditTextPreference to handle these changes and invoke our callbacks.
            Preference locationPreference = findPreference(getString(R.string.pref_location_key));
            setPreferenceSummary(locationPreference, address);

            // Add attributions for our new PlacePicker location.
            if (mAttribution != null) {
                mAttribution.setVisibility(View.VISIBLE);
            } else {
                // For pre-Honeycomb devices, we cannot add a footer, so we will use a snackbar
                View rootView = findViewById(android.R.id.content);
                Snackbar.make(rootView, getString(R.string.attribution_text),
                        Snackbar.LENGTH_LONG).show();
            }

            Utility.resetLocationStatus(this);
            SunshineSyncAdapter.syncImmediately(this);
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
 
Example #11
Source File: SettingsFragment.java    From BackPackTrackII with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ACTIVITY_PICKPLACE && resultCode == Activity.RESULT_OK) {
        Place place = PlacePicker.getPlace(getActivity(), data);
        final CharSequence name = place.getName();
        LatLng ll = place.getLatLng();
        if (name == null || ll == null)
            return;

        // Build location
        final Location location = new Location("place");
        location.setLatitude(ll.latitude);
        location.setLongitude(ll.longitude);
        location.setTime(System.currentTimeMillis());

        // Get settings
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
        final boolean altitude_waypoint = prefs.getBoolean(PREF_ALTITUDE_WAYPOINT, DEFAULT_ALTITUDE_WAYPOINT);

        new AsyncTask<Object, Object, Object>() {
            protected Object doInBackground(Object... params) {
                int altitude_type = (location.hasAltitude() ? BackgroundService.ALTITUDE_GPS : BackgroundService.ALTITUDE_NONE);

                // Add elevation data
                if (!location.hasAltitude() && Util.isConnected(getActivity())) {
                    if (altitude_waypoint)
                        try {
                            GoogleElevationApi.getElevation(location, getActivity());
                            altitude_type = BackgroundService.ALTITUDE_LOOKUP;
                        } catch (Throwable ex) {
                            Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                        }
                }

                if (altitude_type != BackgroundService.ALTITUDE_NONE)
                    altitude_type |= BackgroundService.ALTITUDE_KEEP;

                // Persist location
                new DatabaseHelper(getActivity()).insertLocation(location, altitude_type, name.toString()).close();
                return null;
            }

            @Override
            protected void onPostExecute(Object result) {
                if (running)
                    Toast.makeText(getActivity(), getString(R.string.msg_added, name.toString()), Toast.LENGTH_SHORT).show();
            }
        }.execute();

    } else if (requestCode == ACTIVITY_PLAY_SERVICES)
        ; // Do nothing

    else
        super.onActivityResult(requestCode, resultCode, data);
}
 
Example #12
Source File: PlacePickerFragment.java    From android-play-places with Apache License 2.0 4 votes vote down vote up
/**
 * Extracts data from PlacePicker result.
 * This method is called when an Intent has been started by calling
 * {@link #startActivityForResult(android.content.Intent, int)}. The Intent for the
 * {@link com.google.android.gms.location.places.ui.PlacePicker} is started with
 * {@link #REQUEST_PLACE_PICKER} request code. When a result with this request code is received
 * in this method, its data is extracted by converting the Intent data to a {@link Place}
 * through the
 * {@link com.google.android.gms.location.places.ui.PlacePicker#getPlace(android.content.Intent,
 * android.content.Context)} call.
 *
 * @param requestCode
 * @param resultCode
 * @param data
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // BEGIN_INCLUDE(activity_result)
    if (requestCode == REQUEST_PLACE_PICKER) {
        // This result is from the PlacePicker dialog.

        // Enable the picker option
        showPickAction(true);

        if (resultCode == Activity.RESULT_OK) {
            /* User has picked a place, extract data.
               Data is extracted from the returned intent by retrieving a Place object from
               the PlacePicker.
             */
            final Place place = PlacePicker.getPlace(data, getActivity());

            /* A Place object contains details about that place, such as its name, address
            and phone number. Extract the name, address, phone number, place ID and place types.
             */
            final CharSequence name = place.getName();
            final CharSequence address = place.getAddress();
            final CharSequence phone = place.getPhoneNumber();
            final String placeId = place.getId();
            String attribution = PlacePicker.getAttributions(data);
            if(attribution == null){
                attribution = "";
            }

            // Update data on card.
            getCardStream().getCard(CARD_DETAIL)
                    .setTitle(name.toString())
                    .setDescription(getString(R.string.detail_text, placeId, address, phone,
                            attribution));

            // Print data to debug log
            Log.d(TAG, "Place selected: " + placeId + " (" + name.toString() + ")");

            // Show the card.
            getCardStream().showCard(CARD_DETAIL);

        } else {
            // User has not selected a place, hide the card.
            getCardStream().hideCard(CARD_DETAIL);
        }

    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
    // END_INCLUDE(activity_result)
}
 
Example #13
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 4 votes vote down vote up
protected void onActivityResult( int requestCode, int resultCode, Intent data ) {
    if( requestCode == PLACE_PICKER_REQUEST && resultCode == RESULT_OK ) {
        displayPlace( PlacePicker.getPlace( data, this ) );
    }
}