Re: Detect field touched

87 views
Skip to first unread message

Support

unread,
Jan 18, 2013, 2:42:09 PM1/18/13
to pdfne...@googlegroups.com
Btw here is the relevant code I currently use:
 

pdfView.setOnTouchListener(new View.OnTouchListener() {

                           @Override

                           public boolean onTouch(View v, MotionEvent event) {

                                  try {

                                         for (PageIterator itr = doc.getPageIterator(); itr.hasNext(); )

                                         {

                                               

 

                                                Page page = (Page)(itr.next());

                                                 

                                                int num_annots = page.getNumAnnots();

                                                for (int i = 0; i < num_annots; ++i)

                                                {

                                                      

                                                       Annot annot = page.getAnnot(i);

                                                      

//                                                     Log.i("annotazione", Integer.toString((int)annot.getRect().getX1()));

//                                                     Log.v("annotazioneType", annot.getSDFObj().get("Subtype").value().getName());

                                                       if (annot.isValid() == false) continue;

                                                         if (annot.getType() == Annot.e_Widget) {

                                                           int page_num = page.getIndex();

                                                           Rect bbox = annot.getRect(); // Integer.toString((int)bbox.getY2()));

                                                           Log.i("getX", Integer.toString((int)event.getX()));

                                                           Log.i("getY", Integer.toString((int)event.getY()));

                                                           pdftron.PDF.Annots.Widget w=new pdftron.PDF.Annots.Widget(annot);

                                                           Field f = w.getField();

                                                           int this_coords[] = {0,0};

                                                        v.getLocationOnScreen(this_coords);

 

                                                        //Log.v("daxh","onTouch_coords: "+this_coords[0]+", "+this_coords[1]);

                                                           String name = f.getName();

//                                                        Log.v("nome campo", name);

                                                           if(bbox.contains((int)event.getX(), (int)event.getY())){

                                                             

                                                                  Log.v("touch", name);

                                                        }

                                                          

                                                         }

                                                }

                                         }

                                  }

                                  catch (Exception e)

                                  {

                                        

                                  }

                                  return false;

                           }

                     });

 

On Friday, January 18, 2013 6:46:17 AM UTC-8, raffaele ruffolo wrote:
When i touch the screen to modify the text of a field ,how  do i understand which field have i selected?
Reply all
Reply to author
Forward
0 new messages