0

I have created a hovering dialog to show to the user, but I am wondering would it be possible to show a dialog and still be able to do things in the outside the dialog?

Thanks in advance for any help! :D

This is my MainActivity:

  mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
                @Override
                public void onMapClick(LatLng point) {
                    if(clicked)
                    {
                        List<Address> addresses = new ArrayList<>();
                        try {
                            addresses = geocoder.getFromLocation(point.latitude, point.longitude,1);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        android.location.Address address = addresses.get(0);
                        if (address != null) {
                            StringBuilder sb = new StringBuilder();
                            for (int i = 0; i < address.getMaxAddressLineIndex(); i++){
                                sb.append(address.getAddressLine(i) + " ");
                            }

                            dialog = new Dialog(context);
                            dialog.setContentView(R.layout.map_dialog);
                            dialog.setTitle("IS THIS YOUR LOCATION?");
                            dialog.setCancelable(true);
                            dialog.setCanceledOnTouchOutside(false);

                            text = (TextView) dialog.findViewById(R.id.textLocations);

                            text.setText(sb.toString());

                            dialog.show();

                            Window window = dialog.getWindow();
                            WindowManager.LayoutParams params = window.getAttributes();
                            params.gravity = Gravity.BOTTOM;
                             window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                            window.setAttributes(params);
                        }
                        mMap.clear();
                        mMap.addMarker(new MarkerOptions().position(point).draggable(false));
                        mMap.moveCamera(CameraUpdateFactory.newLatLng(point));
                    }
                }
            });
Gionne Lapuz
  • 518
  • 1
  • 9
  • 23

2 Answers2

0

Do only one thing...

dialog.setCancelable(false);
KuLdip PaTel
  • 1,069
  • 7
  • 19
  • Please add some explanation to your answer. – ItamarG3 May 16 '17 at 13:20
  • Actually sir. If I do that it will only not make the dialog close, but what I am actually asking is that even though the dialog is showing, I will be able to manipulate everything behind the dialog sir :D But thanks for the help sir! – Gionne Lapuz May 16 '17 at 13:36
0

I had once done something similar (or rather I tried to do it.). You see you can Override your Dialog's dispatchTouchEvent(event) and pass the event to your Activity's dispatchTouchEvent(event). While this did provide a user experience where I could get touch events in my Views underneath the Dialog. I was unable to get OnItemClick() callbacks on ListViews and GridViews even though I could scroll. Clicks, Scrolling, etc. worked on all other Views my app had.

So just get a reference to your Activity in your Dialog and pass the event.

@Override
dispatchTouchEvent(MotionEvent event) {
    activity.dispatchTouchEvent(event);
}
Abbas
  • 3,529
  • 5
  • 36
  • 64
  • Well sir I found the solution and it was making the dialog modal. But since I am able to manipulate things in background, the map lags when I move it now another problem haha. But thanks for the help anyway sir :D – Gionne Lapuz May 16 '17 at 13:40