1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
package com.javispedro.vndroid;
import android.app.Activity;
import android.content.Intent;
import android.media.projection.MediaProjectionManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
public class SetupActivity extends AppCompatActivity {
private static String TAG = SetupActivity.class.getSimpleName();
private static final int REQUEST_MEDIA_PROJECTION = 1;
private boolean mirror = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setup);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch (requestCode) {
case REQUEST_MEDIA_PROJECTION:
if (resultCode != Activity.RESULT_OK) {
Log.w(TAG, "User cancelled media projection");
return;
}
notifyMediaProjectionResult(resultCode, data);
startServer();
break;
}
}
private void startServer()
{
Intent intent = new Intent(this, ServerService.class);
intent.setAction(ServerService.ACTION_START);
startService(intent);
}
private void stopServer()
{
Intent intent = new Intent(this, ServerService.class);
intent.setAction(ServerService.ACTION_STOP);
startService(intent);
}
private void notifyMediaProjectionResult(int resultCode, Intent resultData)
{
Intent intent = new Intent(this, ServerService.class);
intent.setAction(ServerService.ACTION_NOTIFY_MEDIA_PROJECTION_RESULT);
intent.putExtra("resultCode", resultCode);
intent.putExtra("resultData", resultData);
startService(intent);
}
public void onStartClick(View view) {
Log.d(TAG, "onStartClick");
if (mirror) {
MediaProjectionManager manager = getSystemService(MediaProjectionManager.class);
startActivityForResult(manager.createScreenCaptureIntent(), REQUEST_MEDIA_PROJECTION);
} else {
startServer();
}
}
public void onStopClick(View view) {
Log.d(TAG, "onStopClick");
stopServer();
}
}
|