Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do I Position Custom Dialog at specific Coordinate?

I'm a noob to android development and I am trying to figure out how to display the NewQuickAction3D popup dialog at a specific coordinate in a view. I am integrating the popup with this tutorial. Essentially, I want to use the popup dialog to display data where the users touch instead painting on the canvas using "infoview" Currently, the popup displays at the top&center of the view that I anchor it to. How can i make it display a particular coordinate? Any help is greatly appreciated.

MY CODE

public void updateMsg(String t_info, float t_x, float t_y, int t_c){
     infoView.updateInfo(t_info, t_x, t_y, t_c); //Infoview paints to on a specific coordinate
     quickAction.show(infoView); //How do I use the t_x & t_y coordinates here instead of just anchoring infoview

EDIT

public void updateMsg(String t_info, float t_x, float t_y, int t_c){
     infoView.updateInfo(t_info, t_x, t_y, t_c);
     WindowManager.LayoutParams wmlp = quickAction.getWindow().getAttributes(); //Error here getting window attributes
     wmlp.gravity = Gravity.TOP | Gravity.LEFT;
         wmlp.x = 100;   //x position
         wmlp.y = 100;   //y position
     quickAction.show(infoView);
}
like image 993
B. Money Avatar asked May 07 '13 12:05

B. Money


People also ask

How to position dialog?

The dialog position can be set using the position property by providing custom X and Y coordinates. The dialog can be positioned inside the target based on the given X and Y values.

How do you change the position of the dialog box in flutter?

You can Use Align widget and align your dialog widget as per your need. Here in example i am setting it to the bottomCenter that is Alignment(0, 1) . Example code: Align( alignment: Alignment(0, 1), child: Material( shape: RoundedRectangleBorder(borderRadius: BorderRadius.

How do I show custom dialog?

This example demonstrate about how to make custom dialog in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.


1 Answers

Override onTouch() of your view

AlertDialog dialog;

    @Override
    public boolean onTouchEvent(MotionEvent event) {
    float x = event.getX();
    float y = event.getY();

    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:

            showDialog();  // display dialog
            break;
        case MotionEvent.ACTION_MOVE:
            if(dialog!=null)
              dialog.dismiss(); 
             // do something
            break;
        case MotionEvent.ACTION_UP:
            // do somethig
            break;
    }
    return true;
    } 
     public void showDialog()
      {

             AlertDialog.Builder builder = new AlertDialog.Builder(FingerPaintActivity.this);
             dialog = builder.create();
             dialog.setTitle("my dialog");
             dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
             WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
         wmlp.gravity = Gravity.TOP | Gravity.LEFT;
             wmlp.x = 100;   //x position
             wmlp.y = 100;   //y position
         dialog.show();
      }

Even to draw user touches the screen then also dialog is displayed. so dismiss dialog in on move.

like image 130
Raghunandan Avatar answered Sep 20 '22 19:09

Raghunandan