-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d233d8
commit b99222e
Showing
50 changed files
with
2,133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ captures/ | |
|
||
# Intellij | ||
*.iml | ||
.idea/workspace.xml | ||
.idea | ||
|
||
# Keystore files | ||
*.jks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/build | ||
google-services.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
|
||
android { | ||
signingConfigs { | ||
|
||
} | ||
compileSdkVersion 24 | ||
buildToolsVersion "24.0.0" | ||
defaultConfig { | ||
applicationId "info.dvkr.screenstream" | ||
minSdkVersion 21 | ||
targetSdkVersion 24 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
resConfigs "en", "ru" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled true | ||
shrinkResources true | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
debug { | ||
minifyEnabled true | ||
shrinkResources true | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
aaptOptions { | ||
cruncherEnabled = false | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(include: ['*.jar'], dir: 'libs') | ||
compile 'com.android.support:appcompat-v7:24.0.0' | ||
compile 'com.google.firebase:firebase-crash:9.2.1' | ||
} | ||
|
||
apply plugin: 'com.google.gms.google-services' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in D:\Android\sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="info.dvkr.screenstream"> | ||
|
||
<uses-feature android:name="android.hardware.wifi" /> | ||
<permission android:name="info.dvkr.screenstream.RECEIVE_BROADCAST" /> | ||
|
||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="info.dvkr.screenstream.RECEIVE_BROADCAST" /> | ||
|
||
<application | ||
android:name=".ApplicationContext" | ||
android:allowBackup="false" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="false" | ||
android:theme="@style/AppTheme"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:launchMode="singleInstance"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
<activity android:name=".SettingsActivity" /> | ||
|
||
<service | ||
android:name=".ForegroundService" | ||
android:exported="false" /> | ||
</application> | ||
|
||
</manifest> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang=en> | ||
<head> | ||
<meta charset=utf-8> | ||
<title>Screen Stream</title> | ||
<style>body,html{width:100%;height:100%;margin:0;border:0;overflow:hidden;display:block}body{background:#EEE}img{position:absolute;top:0;bottom:0;left:0;right:0;margin:auto;max-height:95vh;max-width:95%}</style> | ||
</head> | ||
<body> | ||
<img src="screen_stream.mjpeg"/> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
167 changes: 167 additions & 0 deletions
167
app/src/main/java/info/dvkr/screenstream/ApplicationContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
package info.dvkr.screenstream; | ||
|
||
import android.app.Application; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.graphics.Point; | ||
import android.media.projection.MediaProjection; | ||
import android.media.projection.MediaProjectionManager; | ||
import android.net.wifi.WifiManager; | ||
import android.util.DisplayMetrics; | ||
import android.view.WindowManager; | ||
|
||
import com.google.firebase.crash.FirebaseCrash; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.util.Locale; | ||
import java.util.concurrent.ConcurrentLinkedQueue; | ||
import java.util.concurrent.LinkedTransferQueue; | ||
|
||
|
||
public class ApplicationContext extends Application { | ||
private static ApplicationContext instance; | ||
|
||
private ApplicationSettings applicationSettings; | ||
private WindowManager windowManager; | ||
private MediaProjectionManager projectionManager; | ||
private MediaProjection mediaProjection; | ||
private int densityDPI; | ||
private String indexHtmlPage; | ||
private byte[] iconBytes; | ||
|
||
private final LinkedTransferQueue<byte[]> JPEGQueue = new LinkedTransferQueue<>(); | ||
private final ConcurrentLinkedQueue<Client> clientQueue = new ConcurrentLinkedQueue<>(); | ||
|
||
private volatile boolean isStreamRunning; | ||
private volatile boolean isForegroundServiceRunning; | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
instance = this; | ||
|
||
applicationSettings = new ApplicationSettings(this); | ||
|
||
windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); | ||
projectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE); | ||
densityDPI = getDensityDPI(); | ||
indexHtmlPage = getIndexHTML(); | ||
setFavicon(); | ||
} | ||
|
||
static ApplicationSettings getApplicationSettings() { | ||
return instance.applicationSettings; | ||
} | ||
|
||
static WindowManager getWindowsManager() { | ||
return instance.windowManager; | ||
} | ||
|
||
static MediaProjectionManager getProjectionManager() { | ||
return instance.projectionManager; | ||
} | ||
|
||
static void setMediaProjection(final int resultCode, final Intent data) { | ||
instance.mediaProjection = instance.projectionManager.getMediaProjection(resultCode, data); | ||
} | ||
|
||
static MediaProjection getMediaProjection() { | ||
return instance.mediaProjection; | ||
} | ||
|
||
static int getScreenDensity() { | ||
return instance.densityDPI; | ||
} | ||
|
||
static float getScale() { | ||
return instance.getResources().getDisplayMetrics().density; | ||
} | ||
|
||
static Point getScreenSize() { | ||
final Point screenSize = new Point(); | ||
instance.windowManager.getDefaultDisplay().getRealSize(screenSize); | ||
return screenSize; | ||
} | ||
|
||
static boolean isStreamRunning() { | ||
return instance.isStreamRunning; | ||
} | ||
|
||
static void setIsStreamRunning(final boolean isRunning) { | ||
instance.isStreamRunning = isRunning; | ||
} | ||
|
||
static boolean isForegroundServiceRunning() { | ||
return instance.isForegroundServiceRunning; | ||
} | ||
|
||
static void setIsForegroundServiceRunning(final boolean isRunning) { | ||
instance.isForegroundServiceRunning = isRunning; | ||
} | ||
|
||
static String getIndexHtmlPage() { | ||
return instance.indexHtmlPage; | ||
} | ||
|
||
static byte[] getIconBytes() { | ||
return instance.iconBytes; | ||
} | ||
|
||
static String getServerAddress() { | ||
return "http://" + instance.getIPAddress() + ":" + instance.applicationSettings.getSeverPort(); | ||
} | ||
|
||
static LinkedTransferQueue<byte[]> getJPEGQueue() { | ||
return instance.JPEGQueue; | ||
} | ||
|
||
static ConcurrentLinkedQueue<Client> getClientQueue() { | ||
return instance.clientQueue; | ||
} | ||
|
||
static boolean isWiFIConnected() { | ||
final WifiManager wifi = (WifiManager) instance.getSystemService(Context.WIFI_SERVICE); | ||
return wifi.getConnectionInfo().getNetworkId() != -1; | ||
} | ||
|
||
// Private methods | ||
private String getIPAddress() { | ||
final int ipInt = ((WifiManager) getSystemService(Context.WIFI_SERVICE)).getConnectionInfo().getIpAddress(); | ||
return String.format(Locale.US, "%d.%d.%d.%d", (ipInt & 0xff), (ipInt >> 8 & 0xff), (ipInt >> 16 & 0xff), (ipInt >> 24 & 0xff)); | ||
} | ||
|
||
private int getDensityDPI() { | ||
final DisplayMetrics displayMetrics = new DisplayMetrics(); | ||
windowManager.getDefaultDisplay().getMetrics(displayMetrics); | ||
return displayMetrics.densityDpi; | ||
} | ||
|
||
private String getIndexHTML() { | ||
final StringBuilder sb = new StringBuilder(); | ||
String line; | ||
try (BufferedReader reader = | ||
new BufferedReader( | ||
new InputStreamReader(getAssets().open("index.html"), "UTF-8") | ||
)) { | ||
while ((line = reader.readLine()) != null) sb.append(line.toCharArray()); | ||
} catch (IOException e) { | ||
FirebaseCrash.report(e); | ||
} | ||
final String html = sb.toString(); | ||
sb.setLength(0); | ||
return html; | ||
} | ||
|
||
private void setFavicon() { | ||
try (InputStream inputStream = getAssets().open("favicon.png")) { | ||
iconBytes = new byte[inputStream.available()]; | ||
inputStream.read(iconBytes); | ||
} catch (IOException e) { | ||
FirebaseCrash.report(e); | ||
} | ||
} | ||
} | ||
|
66 changes: 66 additions & 0 deletions
66
app/src/main/java/info/dvkr/screenstream/ApplicationSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package info.dvkr.screenstream; | ||
|
||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.preference.PreferenceManager; | ||
|
||
final class ApplicationSettings { | ||
private static final String DEFAULT_SERVER_PORT = "8080"; | ||
private static final String DEFAULT_JPEG_QUALITY = "80"; | ||
private static final String DEFAULT_CLIENT_TIMEOUT = "3000"; | ||
|
||
private final SharedPreferences sharedPreferences; | ||
|
||
private boolean minimizeOnStream; | ||
private boolean pauseOnSleep; | ||
private volatile int severPort; | ||
private volatile int jpegQuality; | ||
private volatile int clientTimeout; | ||
|
||
ApplicationSettings(Context context) { | ||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); | ||
|
||
minimizeOnStream = sharedPreferences.getBoolean("minimize_on_stream", true); | ||
pauseOnSleep = sharedPreferences.getBoolean("pause_on_sleep", false); | ||
severPort = Integer.parseInt(sharedPreferences.getString("port_number", DEFAULT_SERVER_PORT)); | ||
jpegQuality = Integer.parseInt(sharedPreferences.getString("jpeg_quality", DEFAULT_JPEG_QUALITY)); | ||
clientTimeout = Integer.parseInt(sharedPreferences.getString("client_connection_timeout", DEFAULT_CLIENT_TIMEOUT)); | ||
} | ||
|
||
boolean updateSettings() { | ||
minimizeOnStream = sharedPreferences.getBoolean("minimize_on_stream", true); | ||
pauseOnSleep = sharedPreferences.getBoolean("pause_on_sleep", false); | ||
|
||
jpegQuality = Integer.parseInt(sharedPreferences.getString("jpeg_quality", DEFAULT_JPEG_QUALITY)); | ||
clientTimeout = Integer.parseInt(sharedPreferences.getString("client_connection_timeout", DEFAULT_CLIENT_TIMEOUT)); | ||
|
||
final int newSeverPort = Integer.parseInt(sharedPreferences.getString("port_number", DEFAULT_SERVER_PORT)); | ||
if (newSeverPort != severPort) { | ||
severPort = newSeverPort; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
boolean isMinimizeOnStream() { | ||
return minimizeOnStream; | ||
} | ||
|
||
boolean isPauseOnSleep() { | ||
return pauseOnSleep; | ||
} | ||
|
||
int getSeverPort() { | ||
return severPort; | ||
} | ||
|
||
int getJpegQuality() { | ||
return jpegQuality; | ||
} | ||
|
||
int getClientTimeout() { | ||
return clientTimeout; | ||
} | ||
} |
Oops, something went wrong.