Create help activity
This commit is contained in:
@@ -7,16 +7,20 @@
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:allowBackup="false"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name=".help.HelpActivity"
|
||||
android:parentActivityName=".MainActivity" />
|
||||
|
||||
<activity
|
||||
android:name=".preference.PreferencesActivity"
|
||||
android:label="@string/title_activity_preferences"
|
||||
android:parentActivityName=".MainActivity"/>
|
||||
android:parentActivityName=".MainActivity" />
|
||||
|
||||
<service
|
||||
android:name=".service.ForegroundService"
|
||||
|
||||
82
app/src/main/assets/help/help.html
Normal file
82
app/src/main/assets/help/help.html
Normal file
@@ -0,0 +1,82 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>TTS Server - Help</title>
|
||||
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
|
||||
</head>
|
||||
<body>
|
||||
<h1>What is it?</h1>
|
||||
<p>
|
||||
TTS Server is an Android-only application that provides a REST-based interface for on-board
|
||||
TTS engine of your device. The application is aimed on home automation and allows you to give
|
||||
a second life to your old smartphone, which can now act as a standalone, all-inclusive web TTS
|
||||
provider for your speech-based home notification system.</p>
|
||||
|
||||
<h1>For what?</h1>
|
||||
<p>
|
||||
Android is provided with a great <b>offline</b> TTS engine for almost every language on the
|
||||
world.
|
||||
If you care about high availability of the web TTS provider or you don't want your notifications
|
||||
go through the Internet to the cloud providers, you can utilise your smartphone to done the job.
|
||||
</p>
|
||||
|
||||
<h1>How does it work?</h1>
|
||||
<p>
|
||||
TTS Server runs a service with HTTP server that exposes endpoints allowing you
|
||||
to perform TTS task. As the Android implements its own process-killer, the application needs
|
||||
to run the service <b>on the foreground</b> (so the notification is always shown)
|
||||
keeping it alive and preventing it from being killed. Because of that, keep in mind that
|
||||
the application might drain your battery, so it is recommended to use it <b>only</b>
|
||||
on the devices being always connected to the power source.
|
||||
</p>
|
||||
|
||||
<h1>Consuming REST interface</h1>
|
||||
<p>
|
||||
So far, the application provides two endpoints: <code>/say</code> and <code>/wave</code>.
|
||||
Each endpoint works with JSON-based body, so each request requires a proper
|
||||
<code>Content-Type</code> header.
|
||||
</p>
|
||||
|
||||
<h2>The <code>/say</code> endpoint</h2>
|
||||
<pre>
|
||||
POST /say
|
||||
{
|
||||
"text": "The text to be spoken",
|
||||
"language": "en_US"
|
||||
}
|
||||
</pre>
|
||||
<p><b>Returns:</b> <code>200 OK</code> with empty body</p>
|
||||
<p>
|
||||
The <code>/say</code> endpoint allows you to perform TTS task using device's speakers or the
|
||||
external ones connected to it via jack, Bluetooth etc. For example if you have some
|
||||
old PC-speakers you are able to connect your device to them via line port and
|
||||
get a complete speech-based notification system.
|
||||
</p>
|
||||
|
||||
<h2>The <code>/wave</code> endpoint</h2>
|
||||
<pre>
|
||||
POST /wave
|
||||
{
|
||||
"text": "The text to be spoken",
|
||||
"language": "en_US"
|
||||
}
|
||||
</pre>
|
||||
<p><b>Returns:</b> <code>200 OK</code> with wave file (<code>Content-Type: audio/x-wav</code>)</p>
|
||||
<p>
|
||||
The <code>/wave</code> endpoint enables you to download a wav file containing speech of the
|
||||
provided text. The goal of this endpoint is to provide interface allowing you establishment
|
||||
of the connection between the TTS Server and some other kind of already running TTS system,
|
||||
which can invoke the HTTP request to your Android device and do something with returned
|
||||
wav file. For example, take a look at
|
||||
<a href="https://github.com/bartlomiej-pluta/node-sonos-http-api">my fork</a> of great
|
||||
<a href="https://github.com/jishi/node-sonos-http-api">Node Sonos HTTP API</a>.
|
||||
I've already written a TTS plugin in my fork allowing me to connect the TTS Server and my
|
||||
Sonos speakers right through the Node Sonos HTTP API, which performs the request
|
||||
to the Android device and puts returned wav file on the Sonos speakers.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
21
app/src/main/assets/help/stylesheet.css
Normal file
21
app/src/main/assets/help/stylesheet.css
Normal file
@@ -0,0 +1,21 @@
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
code {
|
||||
background-color: #EFEFEF;
|
||||
color: #757575;
|
||||
padding: 0.2rem 0.5rem;
|
||||
border-radius: 0.2rem;
|
||||
}
|
||||
|
||||
pre {
|
||||
background-color: #EFEFEF;
|
||||
color: #757575;
|
||||
padding: 1rem;
|
||||
border-radius: 0.1rem;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #8BC34A
|
||||
}
|
||||
@@ -1,16 +1,19 @@
|
||||
package io.bartek
|
||||
|
||||
import android.content.*
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.widget.AppCompatImageButton
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import io.bartek.help.HelpActivity
|
||||
import io.bartek.preference.PreferencesActivity
|
||||
import io.bartek.service.ForegroundService
|
||||
import io.bartek.service.ServiceState
|
||||
@@ -38,6 +41,7 @@ class MainActivity : AppCompatActivity() {
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when(item.itemId) {
|
||||
R.id.open_preferences -> startActivity(Intent(this, PreferencesActivity::class.java))
|
||||
R.id.open_help -> startActivity(Intent(this, HelpActivity::class.java))
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item)
|
||||
|
||||
30
app/src/main/java/io/bartek/help/HelpActivity.kt
Normal file
30
app/src/main/java/io/bartek/help/HelpActivity.kt
Normal file
@@ -0,0 +1,30 @@
|
||||
package io.bartek.help
|
||||
|
||||
import android.os.Bundle
|
||||
import android.webkit.WebView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import io.bartek.R
|
||||
import java.util.*
|
||||
|
||||
class HelpActivity : AppCompatActivity() {
|
||||
private lateinit var helpView: WebView
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_help)
|
||||
helpView = findViewById(R.id.help_view)
|
||||
loadHelp()
|
||||
}
|
||||
|
||||
private fun loadHelp() {
|
||||
val lang = Locale.getDefault().language
|
||||
val file = HELP_FILE.format(".$lang")
|
||||
.takeIf { resources.assets.list("help")?.contains(it) == true }
|
||||
?: HELP_FILE.format("")
|
||||
helpView.loadUrl("file:///android_asset/help/${file}")
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val HELP_FILE = "help%s.html"
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package io.bartek.preference
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import io.bartek.R
|
||||
|
||||
class PreferencesActivity : AppCompatActivity() {
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M19.1,12.9a2.8,2.8 0,0 0,0.1 -0.9,2.8 2.8,0 0,0 -0.1,-0.9l2.1,-1.6a0.7,0.7 0,0 0,0.1 -0.6L19.4,5.5a0.7,0.7 0,0 0,-0.6 -0.2l-2.4,1a6.5,6.5 0,0 0,-1.6 -0.9l-0.4,-2.6a0.5,0.5 0,0 0,-0.5 -0.4H10.1a0.5,0.5 0,0 0,-0.5 0.4L9.3,5.4a5.6,5.6 0,0 0,-1.7 0.9l-2.4,-1a0.4,0.4 0,0 0,-0.5 0.2l-2,3.4c-0.1,0.2 0,0.4 0.2,0.6l2,1.6a2.8,2.8 0,0 0,-0.1 0.9,2.8 2.8,0 0,0 0.1,0.9L2.8,14.5a0.7,0.7 0,0 0,-0.1 0.6l1.9,3.4a0.7,0.7 0,0 0,0.6 0.2l2.4,-1a6.5,6.5 0,0 0,1.6 0.9l0.4,2.6a0.5,0.5 0,0 0,0.5 0.4h3.8a0.5,0.5 0,0 0,0.5 -0.4l0.3,-2.6a5.6,5.6 0,0 0,1.7 -0.9l2.4,1a0.4,0.4 0,0 0,0.5 -0.2l2,-3.4c0.1,-0.2 0,-0.4 -0.2,-0.6ZM12,15.6A3.6,3.6 0,1 1,15.6 12,3.6 3.6,0 0,1 12,15.6Z"/>
|
||||
</vector>
|
||||
12
app/src/main/res/layout/activity_help.xml
Normal file
12
app/src/main/res/layout/activity_help.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".help.HelpActivity">
|
||||
|
||||
<WebView
|
||||
android:id="@+id/help_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item android:id="@+id/open_preferences" android:icon="@drawable/ic_settings" app:showAsAction="always" android:title="Preferences" />
|
||||
<item android:id="@+id/open_preferences" app:showAsAction="never" android:title="@string/menu_settings" />
|
||||
<item android:id="@+id/open_help" app:showAsAction="never" android:title="@string/menu_help" />
|
||||
</menu>
|
||||
@@ -22,4 +22,6 @@
|
||||
<string name="preference_tts_title">TTS engine settings</string>
|
||||
<string name="preference_category_tts">TTS engine</string>
|
||||
<string name="preference_category_server">Server</string>
|
||||
<string name="menu_settings">Settings</string>
|
||||
<string name="menu_help">Help</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user