在 Android 中使用 OnGestureDetection 和 Presentation API 在第二个屏幕上绘图?
Draw on second Screen using OnGestureDetection and Presentation API in Android?
目前我有一个设置,其中包括通过 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 屏幕上显示它。
我不是 Android 专家,所以我真的不知道如何正确设置布局,因为我在一个屏幕上处于活动状态,而某些内容必须显示在另一个屏幕上。
顺便说一句,首屏的背景是一张图片..
有人熟悉这个吗?
更新:
我试图将这两个功能结合起来,但我几乎不可能实现它。一个 (canvas) 扩展了 View,另一个 Presentation 似乎不能很好地协同工作。我如何创建视图并将 X/Y-Coordinates 显示为第二个屏幕上的圆圈?有什么想法吗?
我找到了解决问题的方法。它的演示部分来自基本演示示例。我无法使用 canvas 来管理它,所以我正在根据 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);
}
}
}
发生的另一个问题:一段时间后,应用程序因内存溢出而崩溃。知道可能是什么问题吗?
目前我有一个设置,其中包括通过 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 屏幕上显示它。
我不是 Android 专家,所以我真的不知道如何正确设置布局,因为我在一个屏幕上处于活动状态,而某些内容必须显示在另一个屏幕上。 顺便说一句,首屏的背景是一张图片..
有人熟悉这个吗?
更新: 我试图将这两个功能结合起来,但我几乎不可能实现它。一个 (canvas) 扩展了 View,另一个 Presentation 似乎不能很好地协同工作。我如何创建视图并将 X/Y-Coordinates 显示为第二个屏幕上的圆圈?有什么想法吗?
我找到了解决问题的方法。它的演示部分来自基本演示示例。我无法使用 canvas 来管理它,所以我正在根据 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);
}
}
}
发生的另一个问题:一段时间后,应用程序因内存溢出而崩溃。知道可能是什么问题吗?