目前我的设置包括智能手机和通过MHL连接的微型投影仪。我可以通过Presentation API将图像发送到投影仪,没有任何问题。但现在我来到了这一点,我必须积极操纵第二个屏幕。我几乎找不到任何信息。
基本上我想结合这两种技巧: https://github.com/vogellacompany/codeexamples-android/blob/master/com.vogella.android.multitouch/src/com/vogella/android/multitouch/MultitouchView.java用于多点触控并绘制触摸的坐标和
http://blog.stylingandroid.com/multiple-displays-part-2/用于在MHL-Screen上显示它。
我不是Android专家,因此我不知道如何正确设置布局,因为我在一个屏幕上处于活动状态,而另一个屏幕上必须显示某些内容。 第一个屏幕的背景是顺便提一下的图像..
有人熟悉这个吗?
更新: 我试图将这两个功能结合起来,但我很难实现它。一个(画布)扩展了视图,另一个演示文稿看起来不能很好地协同工作。如何在第二个屏幕上创建视图并将X / Y坐标显示为圆圈?有什么想法吗?
答案 0 :(得分:0)
我找到了一种解决问题的解决方案。它的演示部分来自基本的演示示例。我无法使用画布来管理它,所以我根据X / Y坐标移动图像。
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问题:一段时间后,应用程序因内存溢出而崩溃..任何想法可能是什么问题?