Draw on second Screen using OnGestureDetection and Presentation API in Android?



Currently I have a setup which consists of a Smartphone and a pico-projector connected via MHL. I can send Images to the projector via the Presentation API with no problems. But now I came to the point, where I have to actively manipulate the second screen. I found hardly any information.

Basically I would like to combine the two techniques: https://github.com/vogellacompany/codeexamples-android/blob/master/com.vogella.android.multitouch/src/com/vogella/android/multitouch/MultitouchView.java for Multitouch and drawing the touched coordinates and

http://blog.stylingandroid.com/multiple-displays-part-2/ for displaying it on the MHL-Screen.

I'm not an Android expert, so I don't really know how to set the layouts correctly, because I'm active on the one screen and something has to be displayed on the other. The background of the first screen is an image by the way..

Is anybody familiar with this?

Update: I've tried to combine the two functions, but it's hardly possible for me to implement it. The one (canvas) extends View, the other Presentation which doesnt work well together it seems. How could I create a view and display the X/Y-Coordinates as a circle on the second screen? Any idea?

1 Answer: 

I found a solution which more less solves the problem. Its presentation part is coming from the basic presentation example. I was not able to manage it using canvas, so I'm moving an image according to X/Y-Coordinates.

public class MainActivity extends Activity {

    //Initiate Presentation
    private DisplayManager mDisplayManager;
    private final SparseArray<RemotePresentation> mActivePresentations = new SparseArray<RemotePresentation>();
    private Display current=null;
    private boolean isFirstRun=true;

    PointF f = new PointF();
    int i = 0;

    protected void onCreate(Bundle savedInstanceState) {



        //Some Presentation stuff - Connect to external Display
        mDisplayManager = (DisplayManager)getSystemService(Context.DISPLAY_SERVICE);

        Display[] displays= mDisplayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);
        if (displays.length != 0) {

            //Setup external Display as default display for Pinholes
            if (current != null || isFirstRun) {
                isFirstRun = false;

        //start presentation
        //showPresentation(current, 1, 1);

    private void showPresentation(Display display, float x, float y) {


            RemotePresentation presentation = new RemotePresentation(this, display);
            presentation.x = x;
            presentation.y = y;
            mActivePresentations.put(display.getDisplayId(), presentation);


    private void hidePresentation(Display display) {
        final int displayId = display.getDisplayId();
        RemotePresentation presentation = mActivePresentations.get(displayId);
        if (presentation == null) {

    public boolean onTouchEvent(MotionEvent event) {

        // get pointer index from the event object
        int pointerIndex = event.getActionIndex();

        // get pointer ID
        int pointerId = event.getPointerId(pointerIndex);

        // get masked (not specific to a pointer) action
        int maskedAction = event.getActionMasked();

        switch (maskedAction) {

            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_POINTER_DOWN: {

            case MotionEvent.ACTION_MOVE: { // a pointer was moved
                if(i >20){                 // Keep it at low memory!
                    f.x = event.getX(pointerIndex);
                    f.y = event.getY(pointerIndex);

                    showPresentation(current, f.x, f.y);
                i = 0;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_POINTER_UP:
            case MotionEvent.ACTION_CANCEL: {


        return true;

class RemotePresentation extends Presentation {
    public RemotePresentation(Context context, Display display) {
        super(context, display);

    private ImageView image;
    float x = 0;
    float y = 0;

    protected void onCreate(Bundle savedInstanceState) {

        image  = (ImageView) findViewById(R.id.imageView1);
        placeImage(x, y);

    private void placeImage(float X, float Y) {




Anoter problem that occurs: After some time, the app crashes due to memory overflow.. any idea what could be the issue?


More Articles

c# - Error when execute storyboard to close a window open in showdialog

I have get back this error when the Storyboard close the window 'This Visual is not connected to a PresentationSource.'my scenario consist in two window and one UserControlthis is window1's xaml code:<Window x:Name="LWindow" x:Class="WpfAppXtesting.WindowTest1" xmlns="http://schemas.microsoft.

Can't we copy shape(s) from a PPT slide to word document in the orginal format in C#?

I tried to copy autoshape from PPT to word. but its copying as picture format. We cant edit the text or shape in word. How to avoid this?Code I m using not giving expected esult:foreach (Microsoft.Office.Interop.PowerPoint.Shape shape in slide.Shapes){ if (targetDoc != null) { shape.Copy();

c# - Extract text from SmartArt in Presentation OpenXml

I need to extract all text from a PowerPoint OpenXml format (pptx) in .net (VB.NET or C#)Like you all know, pptx is a zipped file whith some folders inside.I'm using OpenXmlPowerTools.I managed to extract the text from the slides folder (slidespart), but I noticed that there is more text in my powe

.net - WPF Databinding Calculated Value sometimes minutes sometimes hours

I have a WPF window with a textbox, using standard WPF Databinding to an object. This all works fine, the issue is this:The user is entering a time estimate, I would like to give the user the option to enter the data in hours or minutes (through a drop down list). I'd like to keep the data in minute

c# - Controlling PowerPoint Slideshow

When a slideshow running in PowerPoint I want to control the movement (Next and Previous) of the slides. Of course it is possible with the > and < button on the keyboard, but is there any way in which I can have a custom application listening to the Next and Previous controls?My custom applicatio

r - Control size of figure in Rstudio presentation

I'm creating a presentation in RStudio (.Rpres). I have a figure that is too large and extends beyond the screen. How can I reduce it?Too big, need to reduce sizeFigure 1========================================================![alt text](fig1)

css - Presenting two paragraphs in HTML side by side

Consider the following problem: you have one text translated into two languages,First line // Unua linioSecond line // Dua linioand there's a need to display them side by side using all available space, make them accessible to search engines as separate paragraphs and allowing separate selection. Th

android - runOnUiThread in Presentation class

How can I update TextView in Presentation class if RunOnUiThread is not available in this class.Here is my exampleprivate final class DemoPresentation extends Presentation { public DemoPresentation(Context context, Display display) { super(context, display); } @Override protected

r - Include googleVis chart in ioslides RStudio

I have a following chart:library(googleVis)df = data.frame(models = c("PLAT", "LC", "APC", "CBD", "M6", "M7", "M8"), val = 1:7)Column <- gvisColumnChart(df)plot(Column)I would like to place it in ioslides in RStudio.Can anyone instruct me how to do it?

Using Android Presentation class with a Bluetooth mouse

I am attempting to use the Presentation class for Android to display a secondary app on another display which can be navigated with the mouse; however, when I connect a Bluetooth mouse to the phone it only shows the cursor and allows for click inputs on the phone's primary display. Is there a way to