Skip to content

Commit c6b6569

Browse files
committed
Update notification images
1 parent 0eb43c7 commit c6b6569

File tree

5 files changed

+63
-47
lines changed

5 files changed

+63
-47
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
# ScreenStream
2-
Screen Stream over HTTP - an Android mobile app: https://play.google.com/store/apps/details?id=info.dvkr.screenstream
2+
**Screen Stream over HTTP** - an Android mobile app: [Screen Stream over HTTP](https://play.google.com/store/apps/details?id=info.dvkr.screenstream)
33

44
The application allows viewing the device screen in your web browser.
55
The main idea is to show your device screen during presentations and demos.
66
No need of any additional software except for this app and a web browser.
7+
78
It uses MJPEG to encode screen images and send them through network socket. So it works with any desktop or mobile browser which supports MJPEG (Chrome, Safari, EDGE, Firefox).
89

910
The program works only via WiFi connection, so your device has to be connected to WiFi. No Internet required, however, there must be a network connection between the client and the device.
10-
The number of client connections is unlimited, but be aware that each of them requires some CPU resources to send data.
11+
The number of client connections is unlimited, but be aware that each of them requires some CPU resources to send data.
1112

1213
It uses Android Cast feature and requires at least Android 5.0 to operate.
1314

15+
**Known problems**
16+
1. On some devices system return image in unknown format. Mostly on devices with no official Android 5.0 or above. Possible Android bug. App will show an error message. Trying to find some workaround.
17+
2. On some devices no notification icon showing but notification is present. Android bug: 213309.
18+
1419
If there are any issues or ideas feel free to contact me.

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ android {
3636

3737
dependencies {
3838
compile fileTree(include: ['*.jar'], dir: 'libs')
39-
compile 'com.android.support:design:24.2.0'
39+
compile 'com.android.support:design:24.2.1'
4040
compile 'com.google.firebase:firebase-crash:9.4.0'
4141
compile 'org.greenrobot:eventbus:3.0.0'
4242
}

app/src/main/java/info/dvkr/screenstream/data/ImageGenerator.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package info.dvkr.screenstream.data;
22

3-
import android.content.Context;
43
import android.graphics.Bitmap;
54
import android.graphics.PixelFormat;
65
import android.hardware.display.DisplayManager;
@@ -20,7 +19,6 @@
2019
import java.io.IOException;
2120

2221
import info.dvkr.screenstream.service.ForegroundService;
23-
import info.dvkr.screenstream.utils.NotifyImageGenerator;
2422

2523
import static info.dvkr.screenstream.ScreenStreamApplication.getAppData;
2624
import static info.dvkr.screenstream.ScreenStreamApplication.getAppPreference;
@@ -148,19 +146,5 @@ public void stop() {
148146
isThreadRunning = false;
149147
}
150148
}
151-
152-
public void addDefaultScreen(final Context context) {
153-
getAppData().getImageQueue().clear();
154-
new Handler().postDelayed(new Runnable() {
155-
@Override
156-
public void run() {
157-
final byte[] jpegByteArray = NotifyImageGenerator.getDefaultScreen(context);
158-
if (jpegByteArray != null) {
159-
getAppData().getImageQueue().add(jpegByteArray);
160-
}
161-
}
162-
}, 500);
163-
164-
}
165149
}
166150

app/src/main/java/info/dvkr/screenstream/utils/NotifyImageGenerator.java renamed to app/src/main/java/info/dvkr/screenstream/data/NotifyImageGenerator.java

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,66 @@
1-
package info.dvkr.screenstream.utils;
1+
package info.dvkr.screenstream.data;
22

33
import android.content.Context;
44
import android.graphics.Bitmap;
55
import android.graphics.Canvas;
66
import android.graphics.Color;
77
import android.graphics.Paint;
88
import android.graphics.Rect;
9+
import android.os.Handler;
10+
import android.support.annotation.Nullable;
911

1012
import com.google.firebase.crash.FirebaseCrash;
1113

1214
import java.io.ByteArrayOutputStream;
1315
import java.io.IOException;
1416

1517
import info.dvkr.screenstream.R;
16-
import info.dvkr.screenstream.data.BusMessages;
1718

1819
import static info.dvkr.screenstream.ScreenStreamApplication.getAppData;
1920
import static info.dvkr.screenstream.ScreenStreamApplication.getAppPreference;
2021

2122
public final class NotifyImageGenerator {
22-
private static int sCurrentScreenSizeX;
23-
private static byte[] sCurrentDefaultScreen;
23+
private Context mContext;
24+
private int mCurrentScreenSizeX;
25+
private byte[] mCurrentDefaultScreen;
2426

25-
public static byte[] getDefaultScreen(final Context context) {
26-
if (sCurrentScreenSizeX != getAppData().getScreenSize().x)
27-
sCurrentDefaultScreen = null;
28-
if (sCurrentDefaultScreen != null) return sCurrentDefaultScreen;
29-
30-
sCurrentDefaultScreen = generateImage(context.getString(R.string.image_generator_press),
31-
context.getString(R.string.main_activity_start_stream).toUpperCase(),
32-
context.getString(R.string.image_generator_on_device));
33-
34-
sCurrentScreenSizeX = getAppData().getScreenSize().x;
35-
return sCurrentDefaultScreen;
27+
public NotifyImageGenerator(final Context context) {
28+
mContext = context;
3629
}
3730

31+
public void addDefaultScreen() {
32+
new Handler().postDelayed(new Runnable() {
33+
@Override
34+
public void run() {
35+
if (mCurrentScreenSizeX != getAppData().getScreenSize().x) {
36+
mCurrentDefaultScreen = null;
37+
}
38+
if (mCurrentDefaultScreen == null) {
39+
mCurrentDefaultScreen = generateImage(mContext.getString(R.string.image_generator_press),
40+
mContext.getString(R.string.main_activity_start_stream).toUpperCase(),
41+
mContext.getString(R.string.image_generator_on_device));
42+
mCurrentScreenSizeX = getAppData().getScreenSize().x;
43+
}
44+
if (mCurrentDefaultScreen != null) {
45+
getAppData().getImageQueue().add(mCurrentDefaultScreen);
46+
}
47+
}
48+
}, 500);
49+
}
3850

39-
public static byte[] getClientNotifyImage(final Context context, final String reason) {
51+
public byte[] getClientNotifyImage(final String reason) {
4052
if (BusMessages.MESSAGE_ACTION_HTTP_RESTART.equals(reason))
41-
return generateImage(context.getString(R.string.image_generator_settings_changed), "", context.getString(R.string.image_generator_go_to_new_address));
53+
return generateImage(mContext.getString(R.string.image_generator_settings_changed),
54+
"", mContext.getString(R.string.image_generator_go_to_new_address));
55+
4256
if (BusMessages.MESSAGE_ACTION_PIN_UPDATE.equals(reason))
43-
return generateImage(context.getString(R.string.image_generator_settings_changed), "", context.getString(R.string.image_generator_reload_this_page));
57+
return generateImage(mContext.getString(R.string.image_generator_settings_changed),
58+
"", mContext.getString(R.string.image_generator_reload_this_page));
4459
return null;
4560
}
4661

4762

63+
@Nullable
4864
private static byte[] generateImage(final String text1, final String text2, final String text3) {
4965
final Bitmap bitmap = Bitmap.createBitmap(getAppData().getScreenSize().x,
5066
getAppData().getScreenSize().y,

app/src/main/java/info/dvkr/screenstream/service/ForegroundService.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import info.dvkr.screenstream.data.BusMessages;
2525
import info.dvkr.screenstream.data.HttpServer;
2626
import info.dvkr.screenstream.data.ImageGenerator;
27-
import info.dvkr.screenstream.utils.NotifyImageGenerator;
27+
import info.dvkr.screenstream.data.NotifyImageGenerator;
2828
import info.dvkr.screenstream.view.MainActivity;
2929

3030
import static info.dvkr.screenstream.ScreenStreamApplication.getAppData;
@@ -40,6 +40,9 @@
4040
public final class ForegroundService extends Service {
4141
private static ForegroundService sServiceInstance;
4242

43+
private static final int NOTIFICATION_START_STREAMING = 10;
44+
private static final int NOTIFICATION_STOP_STREAMING = 11;
45+
4346
private static final String EXTRA_SERVICE_MESSAGE = "info.dvkr.screenstream.extras.EXTRA_SERVICE_MESSAGE";
4447
private static final String SERVICE_MESSAGE_PREPARE_STREAMING = "SERVICE_MESSAGE_PREPARE_STREAMING";
4548

@@ -53,6 +56,7 @@ public final class ForegroundService extends Service {
5356
private MediaProjection.Callback mProjectionCallback;
5457
private HttpServer mHttpServer;
5558
private ImageGenerator mImageGenerator;
59+
private NotifyImageGenerator mNotifyImageGenerator;
5660
private ForegroundServiceHandler mForegroundServiceTaskHandler;
5761
private BroadcastReceiver mLocalNotificationReceiver;
5862
private BroadcastReceiver mBroadcastReceiver;
@@ -98,7 +102,9 @@ public void onStop() {
98102
};
99103
mHttpServer = new HttpServer();
100104
mImageGenerator = new ImageGenerator();
101-
mImageGenerator.addDefaultScreen(getApplicationContext());
105+
getAppData().getImageQueue().clear();
106+
mNotifyImageGenerator = new NotifyImageGenerator(getApplicationContext());
107+
mNotifyImageGenerator.addDefaultScreen();
102108

103109
// Starting thread Handler
104110
final HandlerThread looperThread =
@@ -178,7 +184,9 @@ public void onReceive(Context context, Intent intent) {
178184
@Override
179185
public int onStartCommand(Intent intent, int flags, int startId) {
180186
if (SERVICE_MESSAGE_PREPARE_STREAMING.equals(intent.getStringExtra(EXTRA_SERVICE_MESSAGE))) {
181-
if (!isServicePrepared) startForeground(110, getNotificationStart());
187+
if (!isServicePrepared) {
188+
startForeground(NOTIFICATION_START_STREAMING, getNotificationStart());
189+
}
182190
isServicePrepared = true;
183191
}
184192
return START_NOT_STICKY;
@@ -205,13 +213,15 @@ public void onMessageEvent(BusMessages busMessage) {
205213
serviceStopStreaming();
206214
break;
207215
case MESSAGE_ACTION_HTTP_RESTART:
208-
mHttpServer.stop(NotifyImageGenerator.getClientNotifyImage(getApplicationContext(), MESSAGE_ACTION_HTTP_RESTART));
209-
mImageGenerator.addDefaultScreen(getApplicationContext());
216+
getAppData().getImageQueue().clear();
217+
mHttpServer.stop(mNotifyImageGenerator.getClientNotifyImage(MESSAGE_ACTION_HTTP_RESTART));
218+
mNotifyImageGenerator.addDefaultScreen();
210219
mHttpServer.start();
211220
break;
212221
case MESSAGE_ACTION_PIN_UPDATE:
213-
mHttpServer.stop(NotifyImageGenerator.getClientNotifyImage(getApplicationContext(), MESSAGE_ACTION_PIN_UPDATE));
214-
mImageGenerator.addDefaultScreen(getApplicationContext());
222+
getAppData().getImageQueue().clear();
223+
mHttpServer.stop(mNotifyImageGenerator.getClientNotifyImage(MESSAGE_ACTION_PIN_UPDATE));
224+
mNotifyImageGenerator.addDefaultScreen();
215225
mHttpServer.start();
216226
break;
217227
default:
@@ -223,17 +233,18 @@ private void serviceStartStreaming() {
223233
if (getAppData().isStreamRunning()) return;
224234
stopForeground(true);
225235
mForegroundServiceTaskHandler.obtainMessage(ForegroundServiceHandler.HANDLER_START_STREAMING).sendToTarget();
226-
startForeground(120, getNotificationStop());
236+
startForeground(NOTIFICATION_STOP_STREAMING, getNotificationStop());
227237
if (mMediaProjection != null) mMediaProjection.registerCallback(mProjectionCallback, null);
228238
}
229239

230240
private void serviceStopStreaming() {
231241
if (!getAppData().isStreamRunning()) return;
232242
stopForeground(true);
233243
mForegroundServiceTaskHandler.obtainMessage(ForegroundServiceHandler.HANDLER_STOP_STREAMING).sendToTarget();
234-
startForeground(110, getNotificationStart());
244+
startForeground(NOTIFICATION_START_STREAMING, getNotificationStart());
235245
if (mMediaProjection != null) mMediaProjection.unregisterCallback(mProjectionCallback);
236-
mImageGenerator.addDefaultScreen(getApplicationContext());
246+
getAppData().getImageQueue().clear();
247+
mNotifyImageGenerator.addDefaultScreen();
237248

238249
if (getAppPreference().isEnablePin() && getAppPreference().isAutoChangePin()) {
239250
getAppPreference().generateAndSaveNewPin();

0 commit comments

Comments
 (0)