7

Here I want to highlight this text using onTouchevent in android

2 Answers2

2

You could use OnTouchListener to get the x and y of the event. Then drawing the screen to a bitmap and using bitmap.getPixel based on the top left display of the letter nd the size of your letters, to see if the next letter(s) next to it are also not spaces.Finally, put a yellow rectangle in between the white and the black lettering or the ones you wish to have highlighted.

jersam515
  • 657
  • 6
  • 22
1

You have to implement the onTouchListener for the button or any view you want. as like below:

implement the OnTouchListener:

public class DrawingActivity extends Activity implements View.OnTouchListener

Then implement the code for view touch action:

 public boolean onTouch(View view, MotionEvent motionEvent) {

    if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){

    }else if(motionEvent.getAction() == MotionEvent.ACTION_MOVE){

    }else if(motionEvent.getAction() == MotionEvent.ACTION_UP){


    }

    return true;
}

Now add the code to open the pdf in to respective action. See this Example for the open pdf:

File file = new File("/sdcard/YOUR_PDF_FILE_PATH_WITH_NAME.pdf"); // give the path of your pdf file
                Uri path = Uri.fromFile(file);
                Intent intentPDF = new Intent(Intent.ACTION_VIEW);                     
                intentPDF.setDataAndType(path, "application/pdf");                     
                intentPDF.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);                      
                try {                         
                    startActivity(intentPDF);                     
                }                      
                catch (ActivityNotFoundException e) {                         
                    Toast.makeText(ListSample.this,                              
                         "No Application Available to View PDF",                              
                         Toast.LENGTH_SHORT).show();                     
                }       

Hope it will helps you. If not then let me know.

Renato Lochetti
  • 4,558
  • 3
  • 32
  • 49
Shreyash Mahajan
  • 23,386
  • 35
  • 116
  • 188
  • see..i have a pdf viewer.but i want to highlight the pdf page.this code is not sutiable... –  Feb 20 '12 at 04:55
  • Why it not suitable ? What you want ? – Shreyash Mahajan Feb 20 '12 at 04:58
  • actually if i touch the pdf page using ontouchlistner,the page should be highlighted with some color....here we want to calculate the screen position and pdf document page position and apply the color.. –  Feb 20 '12 at 05:00
  • Ohhh ok. Now i get properly what you want. . . but it depend on your pdf viewer. Some pdf Software are able to edit it SO you can do it. And other option is you have to call that pdf as Image and draw the highlighted color on it. But if you want to save that highlighted pdf then it will be image not the pdf. So be sure what you want to do. – Shreyash Mahajan Feb 20 '12 at 05:05
  • But i dont know how to implement this...highlight in my pdf viewer –  Feb 20 '12 at 05:10
  • how to draw the color like some underline in my page view if i touch the page position.i am using paint,rectangle and canvas,but it should be overlapped in my pdf page.the page is hiding when i use paint and canvas –  Feb 20 '12 at 05:12
  • Ok. But after highlight on that pdf, do you want to save that pdf ? – Shreyash Mahajan Feb 20 '12 at 05:12
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/7930/discussion-between-idroid-explorer-and-raj) – Shreyash Mahajan Feb 20 '12 at 05:14
  • If you have done with the paint on the pdf and if it hides your pdf text then just use little transperent color. it will saw your text of pdf and will seen like highlighted. Enjoy. – Shreyash Mahajan Feb 20 '12 at 05:43