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?
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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.toucheventlayout);
//setContentView(R.layout.layout_mainactivity);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//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;
current=displays[0];
}
}
//start presentation
//showPresentation(current, 1, 1);
}
private void showPresentation(Display display, float x, float y) {
if(display!=null){
RemotePresentation presentation = new RemotePresentation(this, display);
presentation.x = x;
presentation.y = y;
mActivePresentations.put(display.getDisplayId(), presentation);
presentation.show();
}
}
private void hidePresentation(Display display) {
final int displayId = display.getDisplayId();
RemotePresentation presentation = mActivePresentations.get(displayId);
if (presentation == null) {
return;
}
presentation.dismiss();
mActivePresentations.delete(displayId);
}
@Override
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: {
break;
}
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;
}
i++;
break;
}
case MotionEvent.ACTION_UP:
hidePresentation(current);
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_CANCEL: {
break;
}
}
return true;
}
class RemotePresentation extends Presentation {
public RemotePresentation(Context context, Display display) {
super(context, display);
}
private ImageView image;
float x = 0;
float y = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.remote_display);
image = (ImageView) findViewById(R.id.imageView1);
placeImage(x, y);
}
private void placeImage(float X, float Y) {
image.setTranslationX(X);
image.setTranslationY(Y);
}
}
}
Anoter problem that occurs: After some time, the app crashes due to memory overflow.. any idea what could be the issue?