Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
labs
netmetr-android
Commits
e759fe1c
Commit
e759fe1c
authored
Mar 01, 2018
by
Drahomír Karchňák
Browse files
Merge branch 'master' into feature-desync-endpoint
parents
988e2825
ca45002c
Pipeline
#42431
passed with stages
in 8 seconds
Changes
22
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
e759fe1c
## Java
*.class
*.war
*.ear
hs_err_pid*
## Android Studio
*.ipr
*.iws
*.iml
.idea/
out/
## Gradle
build/
.gradle/
*.iml
gradle.properties
## OS Specific
.DS_Store
## General
*.zip
RMBTAndroid/AndroidManifest.xml
View file @
e759fe1c
...
...
@@ -16,8 +16,6 @@
-->
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
package=
"cz.nic.netmetr"
android:versionCode=
"100"
android:versionName=
"1.0.0"
android:installLocation=
"auto"
>
<uses-sdk
android:minSdkVersion=
"15"
android:targetSdkVersion=
"22"
/>
...
...
@@ -80,7 +78,6 @@
<meta-data
android:name=
"com.google.android.maps.v2.API_KEY"
android:value=
"GOOGLEMAPS_APIKEY"
/>
<meta-data
android:name=
"com.google.android.gms.version"
android:value=
"@integer/google_play_services_version"
/>
<meta-data
android:name=
"com.crashlytics.ApiKey"
android:value=
"RMBT_CRASHLYTICS_APIKEY"
/>
<meta-data
android:name=
"cz.nic.labs.rmbt.android.test.RMBTBugReport"
android:value=
"RMBT_USE_BUGREPORT"
/>
</application>
...
...
RMBTAndroid/build.gradle
View file @
e759fe1c
...
...
@@ -16,12 +16,15 @@
buildscript
{
repositories
{
jcenter
()
mavenCentral
()
maven
{
url
'http://download.crashlytics.com/maven'
}
maven
{
url
'https://maven.google.com/'
name
'Google'
}
}
dependencies
{
classpath
'com.android.tools.build:gradle:1.2.+'
classpath
'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
classpath
'com.android.tools.build:gradle:3.0.1'
}
}
...
...
@@ -29,13 +32,11 @@ subprojects {
evaluationDependsOn
(
':RMBTClient'
)
}
apply
plugin:
'android'
apply
plugin:
'crashlytics'
apply
plugin:
'com.android.application'
repositories
{
mavenCentral
()
maven
{
url
'http://repository.pentaho.org/artifactory/repo/'
}
maven
{
url
'http://download.crashlytics.com/maven'
}
}
dependencies
{
...
...
@@ -44,12 +45,11 @@ dependencies {
compile
'com.google.android.gms:play-services:4.+'
// Not supported in Eclipse now. Needs to install Google play Services from Android SDK Manager and use it as a library project.
compile
'dnsjava:dnsjava:2.1.6'
compile
'net.sf.jopt-simple:jopt-simple:3.2'
compile
'com.crashlytics.android:crashlytics:1.+'
}
task
prepareDebugVersion
(
dependsOn:
'processDebugManifest'
)
{
doLast
{
//TODO - Find a better way
// google maps
File
manifest
=
file
(
"${buildDir}/intermediates/manifests/full/debug/AndroidManifest.xml"
)
String
manifestContent
=
manifest
.
getText
(
'UTF-8'
)
...
...
@@ -57,41 +57,12 @@ task prepareDebugVersion(dependsOn: 'processDebugManifest') {
manifestContent
=
manifestContent
.
replaceAll
(
/GOOGLEMAPS_APIKEY/
,
RMBT_GOOGLEMAPS_APIKEY
)
}
manifest
.
write
(
manifestContent
,
'UTF-8'
)
// control server
File
values
=
file
(
"${buildDir}/intermediates/res/debug/values/values.xml"
)
String
valuesContent
=
values
.
getText
(
'UTF-8'
)
if
(
project
.
hasProperty
(
'RMBT_CONTROL_HOST'
))
{
valuesContent
=
valuesContent
.
replaceAll
(
/CONTROL_HOST/
,
RMBT_CONTROL_HOST
)
}
if
(
project
.
hasProperty
(
'RMBT_CONTROL_IPV4_HOST'
))
{
valuesContent
=
valuesContent
.
replaceAll
(
/CONTROL_IPV4_HOST/
,
RMBT_CONTROL_IPV4_HOST
)
}
if
(
project
.
hasProperty
(
'RMBT_CONTROL_IPV6_HOST'
))
{
valuesContent
=
valuesContent
.
replaceAll
(
/CONTROL_IPV6_HOST/
,
RMBT_CONTROL_IPV6_HOST
)
}
if
(
project
.
hasProperty
(
'RMBT_CONTROL_IPV4_CHECK_HOST'
))
{
valuesContent
=
valuesContent
.
replaceAll
(
/CONTROL_IPV4_CHECK_HOST/
,
RMBT_CONTROL_IPV4_CHECK_HOST
)
}
if
(
project
.
hasProperty
(
'RMBT_CONTROL_IPV6_CHECK_HOST'
))
{
valuesContent
=
valuesContent
.
replaceAll
(
/CONTROL_IPV6_CHECK_HOST/
,
RMBT_CONTROL_IPV6_CHECK_HOST
)
}
if
(
project
.
hasProperty
(
'RMBT_CONTROL_PORT'
))
{
valuesContent
=
valuesContent
.
replaceAll
(
/RMBT_CONTROL_PORT/
,
RMBT_CONTROL_PORT
)
}
if
(
project
.
hasProperty
(
'RMBT_CONTROL_SSL'
))
{
valuesContent
=
valuesContent
.
replaceAll
(
/RMBT_CONTROL_SSL/
,
RMBT_CONTROL_SSL
)
}
if
(
project
.
hasProperty
(
'RMBT_QOS_SSL'
))
{
valuesContent
=
valuesContent
.
replaceAll
(
/RMBT_QOS_SSL/
,
RMBT_QOS_SSL
)
}
values
.
write
(
valuesContent
,
'UTF-8'
)
}
}
task
prepareReleaseVersion
(
dependsOn:
'processReleaseManifest'
)
{
doLast
{
//TODO - Find a better way
// google maps
File
manifest
=
file
(
"${buildDir}/intermediates/manifests/full/release/AndroidManifest.xml"
)
String
manifestContent
=
manifest
.
getText
(
'UTF-8'
)
...
...
@@ -99,81 +70,37 @@ task prepareReleaseVersion(dependsOn: 'processReleaseManifest') {
manifestContent
=
manifestContent
.
replaceAll
(
/GOOGLEMAPS_APIKEY/
,
RMBT_GOOGLEMAPS_APIKEY
)
}
manifest
.
write
(
manifestContent
,
'UTF-8'
)
// control server
File
values
=
file
(
"${buildDir}/intermediates/res/release/values/values.xml"
)
String
valuesContent
=
values
.
getText
(
'UTF-8'
)
if
(
project
.
hasProperty
(
'RMBT_CONTROL_HOST'
))
{
valuesContent
=
valuesContent
.
replaceAll
(
/CONTROL_HOST/
,
RMBT_CONTROL_HOST
)
}
if
(
project
.
hasProperty
(
'RMBT_CONTROL_IPV4_HOST'
))
{
valuesContent
=
valuesContent
.
replaceAll
(
/CONTROL_IPV4_HOST/
,
RMBT_CONTROL_IPV4_HOST
)
}
if
(
project
.
hasProperty
(
'RMBT_CONTROL_IPV6_HOST'
))
{
valuesContent
=
valuesContent
.
replaceAll
(
/CONTROL_IPV6_HOST/
,
RMBT_CONTROL_IPV6_HOST
)
}
if
(
project
.
hasProperty
(
'RMBT_CONTROL_IPV4_CHECK_HOST'
))
{
valuesContent
=
valuesContent
.
replaceAll
(
/CONTROL_IPV4_CHECK_HOST/
,
RMBT_CONTROL_IPV4_CHECK_HOST
)
}
if
(
project
.
hasProperty
(
'RMBT_CONTROL_IPV6_CHECK_HOST'
))
{
valuesContent
=
valuesContent
.
replaceAll
(
/CONTROL_IPV6_CHECK_HOST/
,
RMBT_CONTROL_IPV6_CHECK_HOST
)
}
if
(
project
.
hasProperty
(
'RMBT_CONTROL_PORT'
))
{
valuesContent
=
valuesContent
.
replaceAll
(
/RMBT_CONTROL_PORT/
,
RMBT_CONTROL_PORT
)
}
if
(
project
.
hasProperty
(
'RMBT_CONTROL_SSL'
))
{
valuesContent
=
valuesContent
.
replaceAll
(
/RMBT_CONTROL_SSL/
,
RMBT_CONTROL_SSL
)
}
if
(
project
.
hasProperty
(
'RMBT_QOS_SSL'
))
{
valuesContent
=
valuesContent
.
replaceAll
(
/RMBT_QOS_SSL/
,
RMBT_QOS_SSL
)
}
values
.
write
(
valuesContent
,
'UTF-8'
)
}
}
task
prepareCrashlyticsDebug
(
dependsOn:
'processDebugManifest'
)
{
doLast
{
// api key
File
manifest
=
file
(
"${buildDir}/intermediates/manifests/full/debug/AndroidManifest.xml"
)
String
manifestContent
=
manifest
.
getText
(
'UTF-8'
)
if
(
project
.
hasProperty
(
'RMBT_CRASHLYTICS_APIKEY'
))
{
manifestContent
=
manifestContent
.
replaceAll
(
/RMBT_CRASHLYTICS_APIKEY/
,
RMBT_CRASHLYTICS_APIKEY
)
}
// bug reporting
if
(
project
.
hasProperty
(
'RMBT_USE_BUGREPORT'
))
{
manifestContent
=
manifestContent
.
replaceAll
(
/RMBT_USE_BUGREPORT/
,
RMBT_USE_BUGREPORT
)
}
manifest
.
write
(
manifestContent
,
'UTF-8'
)
// api secret
if
(
project
.
hasProperty
(
'RMBT_CRASHLYTICS_APISECRET'
))
{
File
crashlytics
=
file
(
"crashlytics.properties"
)
crashlytics
.
write
(
/apiSecret=/
+
RMBT_CRASHLYTICS_APISECRET
,
'UTF-8'
)
}
}
}
task
prepareCrashlyticsRelease
(
dependsOn:
'processReleaseManifest'
)
{
doLast
{
// api key
File
manifest
=
file
(
"${buildDir}/intermediates/manifests/full/release/AndroidManifest.xml"
)
String
manifestContent
=
manifest
.
getText
(
'UTF-8'
)
if
(
project
.
hasProperty
(
'RMBT_CRASHLYTICS_APIKEY'
))
{
manifestContent
=
manifestContent
.
replaceAll
(
/RMBT_CRASHLYTICS_APIKEY/
,
RMBT_CRASHLYTICS_APIKEY
)
}
// bug reporting
if
(
project
.
hasProperty
(
'RMBT_USE_BUGREPORT'
))
{
manifestContent
=
manifestContent
.
replaceAll
(
/RMBT_USE_BUGREPORT/
,
RMBT_USE_BUGREPORT
)
}
manifest
.
write
(
manifestContent
,
'UTF-8'
)
// api secret
if
(
project
.
hasProperty
(
'RMBT_CRASHLYTICS_APISECRET'
))
{
File
crashlytics
=
file
(
"crashlytics.properties"
)
crashlytics
.
write
(
/apiSecret=/
+
RMBT_CRASHLYTICS_APISECRET
,
'UTF-8'
)
}
}
}
//TODO - Find a better way
//task prepareCrashlyticsDebug(dependsOn: 'processDebugManifest') {
// doLast{
// // api key
// File manifest = file("${buildDir}/intermediates/manifests/full/debug/AndroidManifest.xml")
// String manifestContent = manifest.getText('UTF-8')
//
// // bug reporting
// if (project.hasProperty('RMBT_USE_BUGREPORT')) {
// manifestContent = manifestContent.replaceAll(/RMBT_USE_BUGREPORT/, RMBT_USE_BUGREPORT)
// }
// manifest.write(manifestContent, 'UTF-8')
// }
//}
//task prepareCrashlyticsRelease(dependsOn: 'processReleaseManifest') {
// doLast{
// // api key
// File manifest = file("${buildDir}/intermediates/manifests/full/release/AndroidManifest.xml")
// String manifestContent = manifest.getText('UTF-8')
//
// // bug reporting
// if (project.hasProperty('RMBT_USE_BUGREPORT')) {
// manifestContent = manifestContent.replaceAll(/RMBT_USE_BUGREPORT/, RMBT_USE_BUGREPORT)
// }
// manifest.write(manifestContent, 'UTF-8')
// }
//}
tasks
.
whenTaskAdded
{
task
->
if
(
task
.
name
==
'processDebugResources'
)
...
...
@@ -185,15 +112,16 @@ tasks.whenTaskAdded { task ->
task
.
dependsOn
prepareReleaseVersion
}
tasks
.
whenTaskAdded
{
task
->
if
(
task
.
name
==
'crashlyticsGenerateResourcesDebug'
)
task
.
dependsOn
prepareCrashlyticsDebug
}
tasks
.
whenTaskAdded
{
task
->
if
(
task
.
name
==
'crashlyticsGenerateResourcesRelease'
)
task
.
dependsOn
prepareCrashlyticsRelease
}
//TODO - Is this necessary?
//tasks.whenTaskAdded { task ->
// if (task.name == 'crashlyticsGenerateResourcesDebug')
// task.dependsOn prepareCrashlyticsDebug
//}
//
//tasks.whenTaskAdded { task ->
// if (task.name == 'crashlyticsGenerateResourcesRelease')
// task.dependsOn prepareCrashlyticsRelease
//}
// copy NDT resources to android debug
tasks
.
whenTaskAdded
{
task
->
...
...
@@ -226,7 +154,6 @@ tasks.whenTaskAdded { task ->
android
{
compileSdkVersion
19
buildToolsVersion
"20"
sourceSets
{
main
{
...
...
@@ -248,13 +175,42 @@ android {
buildTypes
.
all
{
buildType
->
buildConfigField
"String"
,
"CLIENT_SECRET"
,
project
.
hasProperty
(
'RMBT_CLIENT_SECRET'
)
?
String
.
format
(
"\"%s\""
,
RMBT_CLIENT_SECRET
)
:
"null"
ext
.
enableCrashlytics
=
project
.
hasProperty
(
'RMBT_CRASHLYTICS_APIKEY'
)
}
defaultConfig
{
targetSdkVersion
19
versionName
getVersionNameFromGit
()
versionCode
getVersionCodeFromGit
()
if
(
project
.
hasProperty
(
'RMBT_CONTROL_IPV4_HOST'
))
{
resValue
'string'
,
'default_control_host'
,
"${RMBT_CONTROL_IPV4_HOST}"
resValue
'string'
,
'default_control_host_ipv4_only'
,
project
.
property
(
'RMBT_CONTROL_IPV4_HOST'
)
}
if
(
project
.
hasProperty
(
'RMBT_CONTROL_IPV6_HOST'
))
{
resValue
'string'
,
'default_control_host_ipv6_only'
,
project
.
property
(
'RMBT_CONTROL_IPV6_HOST'
)
}
if
(
project
.
hasProperty
(
'RMBT_CONTROL_IPV4_CHECK_HOST'
))
{
resValue
'string'
,
'default_control_check_ipv4_url'
,
project
.
property
(
'RMBT_CONTROL_IPV4_CHECK_HOST'
)
}
if
(
project
.
hasProperty
(
'RMBT_CONTROL_IPV6_CHECK_HOST'
))
{
resValue
'string'
,
'default_control_check_ipv6_url'
,
project
.
property
(
'RMBT_CONTROL_IPV6_CHECK_HOST'
)
}
if
(
project
.
hasProperty
(
'RMBT_CONTROL_PORT'
))
{
resValue
'string'
,
'default_control_port'
,
project
.
property
(
'RMBT_CONTROL_PORT'
)
}
if
(
project
.
hasProperty
(
'RMBT_CONTROL_SSL'
))
{
resValue
'string'
,
'default_control_ssl'
,
project
.
property
(
'RMBT_CONTROL_SSL'
)
}
if
(
project
.
hasProperty
(
'RMBT_QOS_SSL'
))
{
resValue
'string'
,
'default_qos_ssl'
,
project
.
property
(
'RMBT_QOS_SSL'
)
}
}
lintOptions
{
...
...
@@ -302,19 +258,9 @@ def getVersionNameFromGit() {
}
def
branchName
=
getBranchNameFromGit
()
return
stdoutVersion
.
toString
().
trim
()
+
'-'
+
branchName
}
def
getVersionCodeFromGit
()
{
def
stdout
=
new
ByteArrayOutputStream
()
exec
{
commandLine
'git'
,
'rev-list'
,
'HEAD'
,
'--count'
standardOutput
=
stdout
}
return
stdout
.
toString
().
trim
().
toInteger
()
}
def
getBranchNameFromGit
()
{
def
stdout
=
new
ByteArrayOutputStream
()
exec
{
...
...
@@ -325,6 +271,16 @@ def getBranchNameFromGit() {
return
branchString
.
contains
(
"/"
)
?
branchString
.
substring
(
branchString
.
lastIndexOf
(
"/"
)
+
1
)
:
branchString
}
def
getVersionCodeFromGit
()
{
def
stdout
=
new
ByteArrayOutputStream
()
exec
{
commandLine
'git'
,
'rev-list'
,
'HEAD'
,
'--count'
standardOutput
=
stdout
}
return
stdout
.
toString
().
trim
().
toInteger
()
}
task
wrapper
(
type:
Wrapper
)
{
gradleVersion
=
'2.4'
}
RMBTAndroid/gradle/wrapper/gradle-wrapper.properties
View file @
e759fe1c
...
...
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath
=
wrapper/dists
zipStoreBase
=
GRADLE_USER_HOME
zipStorePath
=
wrapper/dists
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-
2.2-bin
.zip
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-
4.1-all
.zip
RMBTAndroid/res/values/defaults.xml
View file @
e759fe1c
...
...
@@ -21,16 +21,4 @@
<integer
name=
"default_loop_min_delay"
>
30
</integer>
<integer
name=
"default_loop_max_delay"
>
900
</integer>
<integer
name=
"default_loop_max_movement"
>
250
</integer>
<string
translatable=
"false"
name=
"default_control_host"
>
CONTROL_IPV4_HOST
</string>
<string
translatable=
"false"
name=
"default_control_host_ipv4_only"
>
CONTROL_IPV4_HOST
</string>
<string
translatable=
"false"
name=
"default_control_host_ipv6_only"
>
CONTROL_IPV6_HOST
</string>
<string
translatable=
"false"
name=
"default_control_check_ipv4_url"
>
CONTROL_IPV4_CHECK_HOST
</string>
<string
translatable=
"false"
name=
"default_control_check_ipv6_url"
>
CONTROL_IPV6_CHECK_HOST
</string>
<string
translatable=
"false"
name=
"default_control_port"
>
RMBT_CONTROL_PORT
</string>
<string
translatable=
"false"
name=
"default_control_ssl"
>
RMBT_CONTROL_SSL
</string>
<string
translatable=
"false"
name=
"default_qos_ssl"
>
RMBT_QOS_SSL
</string>
</resources>
RMBTAndroid/src/at/alladin/rmbt/android/main/RMBTMainActivity.java
View file @
e759fe1c
...
...
@@ -47,7 +47,6 @@ import org.json.JSONArray;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
com.crashlytics.android.Crashlytics
;
import
com.google.android.gms.maps.model.LatLng
;
import
android.app.ActionBar
;
...
...
@@ -345,19 +344,19 @@ public class RMBTMainActivity extends Activity implements MapProperties, RMBTLoo
@Override
public
void
onCreate
(
final
Bundle
savedInstanceState
)
{
//Log.i("MAIN ACTIVITY", "onCreate");
restoreInstance
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
// BUG REPORT
try
{
boolean
bugReportEnabled
=
getPackageManager
().
getApplicationInfo
(
getPackageName
(),
PackageManager
.
GET_META_DATA
).
metaData
.
getBoolean
(
BUG_REPORT_MANIFEST_PROPERTY
,
false
);
if
(
bugReportEnabled
)
{
Crashlytics
.
start
(
this
);
}
}
catch
(
NameNotFoundException
e
)
{
// nothing needed
}
// TODO - Add Sentry
// try {
// boolean bugReportEnabled = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA).metaData.getBoolean(BUG_REPORT_MANIFEST_PROPERTY, false);
// if (bugReportEnabled) {
// Crashlytics.start(this);
// }
// } catch (NameNotFoundException e) {
// // nothing needed
// }
NetworkInfoCollector
.
init
(
this
);
networkInfoCollector
=
NetworkInfoCollector
.
getInstance
();
...
...
RMBTStatisticServer/src/at/alladin/rmbt/statisticServer/StatisticServer.java
View file @
e759fe1c
...
...
@@ -24,6 +24,7 @@ import org.restlet.routing.Template;
import
at.alladin.rmbt.statisticServer.export.ExportDirtyResource
;
import
at.alladin.rmbt.statisticServer.export.ExportResource
;
import
at.alladin.rmbt.statisticServer.export.TestExportResource
;
import
at.alladin.rmbt.statisticServer.export.ImageExport
;
import
at.alladin.rmbt.statisticServer.report.TestReport
;
public
class
StatisticServer
extends
Application
...
...
@@ -67,7 +68,7 @@ public class StatisticServer extends Application
router
.
attach
(
"/exportDirty/NetMetr-opendata-dirty-{year}-{month}."
,
ExportDirtyResource
.
class
,
Template
.
MODE_STARTS_WITH
);
router
.
attach
(
"/export"
,
ExportResource
.
class
,
Template
.
MODE_STARTS_WITH
);
//
router.attach("/{lang}/{open_test_uuid}/{size}.png", ImageExport.class);
router
.
attach
(
"/{lang}/{open_test_uuid}/{size}.png"
,
ImageExport
.
class
);
// administrative resources (access restrictions might be applied to /admin/
...
...
RMBTStatisticServer/src/at/alladin/rmbt/statisticServer/export/AbstractImageGenerator.java
0 → 100644
View file @
e759fe1c
package
at.alladin.rmbt.statisticServer.export
;
import
java.awt.Font
;
import
java.awt.FontFormatException
;
import
java.awt.FontMetrics
;
import
java.awt.Graphics
;
import
java.awt.image.BufferedImage
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.text.FieldPosition
;
import
java.text.Format
;
import
java.util.Locale
;
import
javax.imageio.ImageIO
;
import
at.alladin.rmbt.shared.SignificantFormat
;
public
abstract
class
AbstractImageGenerator
{
private
static
final
String
TEMPLATES_PATH
=
"templates/"
;
private
static
final
String
FONT_PATH
=
"fonts/"
;
private
static
final
String
FALLBACK_FONT_NAME
=
"Droid Sans"
;
/**
* Generates a image for showing the user its speed test result
* @param lang: Language of the image, currently either 'de' or 'en'
* @param upload: Upload speed in mbps
* @param download: Download speed in mbps
* @param ping: Ping in ms
* @param isp: ISP name
* @param typ: Test type (LAN, 3G, 4G, etc.)
* @param signal: Signal strength in dbm
* @param os: Plattform used for conducting the test (Android, IOS, Applet, Browser)
* @return rendered image
*/
public
abstract
BufferedImage
generateImage
(
String
lang
,
double
upload
,
double
download
,
double
ping
,
String
isp
,
String
typ
,
String
signal
,
String
os
,
String
formattedTime
,
String
formattedDate
)
throws
IOException
;
protected
BufferedImage
loadTemplateImage
(
String
name
)
throws
IOException
{
return
ImageIO
.
read
(
super
.
getClass
().
getResourceAsStream
(
TEMPLATES_PATH
+
name
));
}
protected
Font
loadFont
(
String
name
)
{
try
{
InputStream
fontInputStream
=
super
.
getClass
().
getResourceAsStream
(
FONT_PATH
+
name
);
return
Font
.
createFont
(
Font
.
TRUETYPE_FONT
,
fontInputStream
);
}
catch
(
FontFormatException
|
IOException
e
)
{
e
.
printStackTrace
();
System
.
out
.
println
(
"Couldn't load font w/ name: "
+
name
+
". Using fallback font!"
);
return
new
Font
(
FALLBACK_FONT_NAME
,
Font
.
PLAIN
,
1
);
}
}
/**
* Formats a number to 2 significant digits
* @param number the number
* @return the formatted number
*/
protected
String
formatNumber
(
double
number
,
String
lang
)
{
final
Locale
locale
=
new
Locale
(
lang
);
final
Format
format
=
new
SignificantFormat
(
2
,
locale
);
final
StringBuffer
buf
=
format
.
format
(
number
,
new
StringBuffer
(),
new
FieldPosition
(
0
));
return
buf
.
toString
();
}
protected
void
drawCenteredString
(
String
s
,
int
x
,
int
y
,
int
w
,
int
h
,
Graphics
g
)
{
FontMetrics
fm
=
g
.
getFontMetrics
();
x
+=
(
w
-
fm
.
stringWidth
(
s
))
/
2
;
y
+=
(
fm
.
getAscent
()
+
(
h
-
(
fm
.
getAscent
()
+
fm
.
getDescent
()))
/
2
);
g
.
drawString
(
s
,
x
,
y
);
}
}
RMBTStatisticServer/src/at/alladin/rmbt/statisticServer/export/ForumBannerGenerator.java
0 → 100644
View file @
e759fe1c
package
at.alladin.rmbt.statisticServer.export
;
import
java.awt.Color
;
import
java.awt.Font
;
import
java.awt.FontMetrics
;
import
java.awt.Graphics2D
;
import
java.awt.RenderingHints
;
import
java.awt.image.BufferedImage
;
import
java.io.IOException
;
public
class
ForumBannerGenerator
extends
AbstractImageGenerator
{
private
static
final
int
BANNER_WIDTH
=
560
;
private
static
final
int
BANNER_HEIGHT
=
274
;
private
static
final
String
UTC_FORMAT
=
"%s UTC"
;
private
static
final
String
TEMPLATE_FORMAT
=
"forumbanner_%s.png"
;
private
static
final
String
PRIMARY_FONT
=
"Roboto-Light.ttf"
;
private
static
final
String
SECONDARY_FONT
=
"Roboto-Medium.ttf"
;
private
Font
primaryFont
=
null
;
private
Font
secondaryFont
=
null
;
private
enum
UnknownValueMapping
{
EN
(
"en"
,
"Unknown"
),
CS
(
"cs"
,
"Neznamé"
),
DE
(
"de"
,
"Unbekannt"
);
private
static
final
String
FALLBACK
=
"n/a"
;
private
final
String
lang
;
private
final
String
unknownValue
;
UnknownValueMapping
(
String
lang
,
String
unknownValue
)
{
this
.
lang
=
lang
;
this
.
unknownValue
=
unknownValue
;
}
protected
static
String
getUnknownValue
(
String
lang
)
{
for
(
UnknownValueMapping
item
:
values
())
{
if
(
item
.
lang
.
equals
(
lang
))
return
item
.
unknownValue
;
}
return
FALLBACK
;
}
}
private
enum
AdditionalValuePositionMapping
{
EN
(
"en"
,
151
,
432
),
CS
(
"cs"
,
130
,
394
),
DE
(
"de"
,
128
,
398
);
private
static
final
AdditionalValuePositionMapping
FALLBACK
=
AdditionalValuePositionMapping
.
EN
;
private
final
String
lang
;
private
final
int
firstColumnX
,
secondColumnX
;
AdditionalValuePositionMapping
(
String
lang
,
int
firstColumnX
,
int
secondColumnX
)
{
this
.
lang
=
lang
;
this
.
firstColumnX
=
firstColumnX
;
this
.
secondColumnX
=
secondColumnX
;
}
protected
static
int
getFirstColumnX
(
String
lang
)
{
for
(
AdditionalValuePositionMapping
item
:
values
())
{
if
(
item
.
lang
.
equals
(
lang
))
return
item
.
firstColumnX
;
}
return
FALLBACK
.
firstColumnX
;
}
protected
static
int
getSecondColumnX
(
String
lang
)
{
for
(
AdditionalValuePositionMapping
item
:
values
())
{
if
(
item
.
lang
.
equals
(
lang
))
return
item
.
secondColumnX
;
}