diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 1012cdd..d02500c 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -34,7 +34,7 @@
android:theme="@style/AppTheme.NoActionBar" />
+ private lateinit var fonts: MutableMap
fun init(context: Context) {
- fonts = mutableListOf()
- DEFAULT_FONT = NeoFont(Typeface.createFromAsset(context.assets, "font.ttf"))
+ File(NeoTermPath.FONT_PATH).mkdirs()
+ fonts = mutableMapOf()
+
+ val defaultFontFile = fontFile(DEFAULT_FONT_NAME)
+ if (!defaultFontFile.exists()) {
+ if (!extractDefaultFont(context, defaultFontFile)) {
+ DEFAULT_FONT = loadDefaultFontFromAsset(context)
+ fonts.put(DEFAULT_FONT_NAME, DEFAULT_FONT)
+ return
+ }
+ }
+
+ if (!refreshFontList()) {
+ DEFAULT_FONT = loadDefaultFontFromAsset(context)
+ fonts.put(DEFAULT_FONT_NAME, DEFAULT_FONT)
+ }
}
fun getDefaultFont(): NeoFont {
@@ -20,6 +41,71 @@ object FontManager {
}
fun getCurrentFont(): NeoFont {
- return getDefaultFont()
+ return fonts[getCurrentFontName()]!!
+ }
+
+ fun setCurrentFont(fontName: String) {
+ NeoPreference.store(R.string.key_customization_font, fontName)
+ }
+
+ fun getCurrentFontName(): String {
+ var currentFontName = NeoPreference.loadString(R.string.key_customization_font, DEFAULT_FONT_NAME)
+ if (!fonts.containsKey(currentFontName)) {
+ currentFontName = DEFAULT_FONT_NAME
+ NeoPreference.store(R.string.key_customization_font, DEFAULT_FONT)
+ }
+ return currentFontName
+ }
+
+ fun getFont(fontName: String): NeoFont {
+ return if (fonts.containsKey(fontName)) fonts[fontName]!! else getCurrentFont()
+ }
+
+ fun getFontNames(): List {
+ val list = ArrayList()
+ list += fonts.keys
+ return list
+ }
+
+ fun refreshFontList(): Boolean {
+ fonts.clear()
+ fonts.put("Android Monospace", NeoFont(Typeface.MONOSPACE))
+ fonts.put("Android Sans Serif", NeoFont(Typeface.SANS_SERIF))
+ fonts.put("Android Serif", NeoFont(Typeface.SERIF))
+ val fontDir = File(NeoTermPath.FONT_PATH)
+ for (file in fontDir.listFiles({ pathname -> pathname.name.endsWith(".ttf") })) {
+ val fontName = fontName(file)
+ val font = NeoFont(file)
+ fonts.put(fontName, font)
+ }
+ if (fonts.containsKey(DEFAULT_FONT_NAME)) {
+ DEFAULT_FONT = fonts[DEFAULT_FONT_NAME]!!
+ return true
+ }
+ return false
+ }
+
+ private fun loadDefaultFontFromAsset(context: Context): NeoFont {
+ return NeoFont(Typeface.createFromAsset(context.assets, "$DEFAULT_FONT_NAME.ttf"))
+ }
+
+ private fun extractDefaultFont(context: Context, defaultFontFile: File): Boolean {
+ try {
+ val assets = context.assets
+ val ttfInput = assets.open("$DEFAULT_FONT_NAME.ttf")
+ FileUtils.writeFile(defaultFontFile, ttfInput)
+ ttfInput.close()
+ return true
+ } catch (e: Exception) {
+ return false
+ }
+ }
+
+ private fun fontFile(fontName: String): File {
+ return File("${NeoTermPath.FONT_PATH}/$fontName.ttf")
+ }
+
+ private fun fontName(fontFile: File): String {
+ return fontFile.nameWithoutExtension
}
}
\ No newline at end of file
diff --git a/app/src/main/java/io/neoterm/customize/font/NeoFont.kt b/app/src/main/java/io/neoterm/customize/font/NeoFont.kt
index e40a5d9..0665fa8 100644
--- a/app/src/main/java/io/neoterm/customize/font/NeoFont.kt
+++ b/app/src/main/java/io/neoterm/customize/font/NeoFont.kt
@@ -1,13 +1,31 @@
package io.neoterm.customize.font
import android.graphics.Typeface
-import io.neoterm.view.TerminalView
+import java.io.File
/**
* @author kiva
*/
-class NeoFont(val typeface: Typeface) {
- fun applyLocal(terminalView: TerminalView?) {
- terminalView?.setTypeface(typeface)
+class NeoFont {
+ private var fontFile: File? = null
+ private var typeface: Typeface? = null
+
+ constructor(fontFile: File) {
+ this.fontFile = fontFile
+ }
+
+ constructor(typeface: Typeface) {
+ this.typeface = typeface
+ }
+
+ fun getTypeFace(): Typeface? {
+ if (typeface == null && fontFile == null) {
+ return null
+ }
+
+ if (typeface == null) {
+ typeface = Typeface.createFromFile(fontFile)
+ }
+ return typeface
}
}
\ No newline at end of file
diff --git a/app/src/main/java/io/neoterm/ui/NeoTermActivity.kt b/app/src/main/java/io/neoterm/ui/NeoTermActivity.kt
index 2aae5a6..d0a4f63 100644
--- a/app/src/main/java/io/neoterm/ui/NeoTermActivity.kt
+++ b/app/src/main/java/io/neoterm/ui/NeoTermActivity.kt
@@ -50,6 +50,7 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
+ NeoPreference.init(this)
NeoPermission.initAppPermission(this, NeoPermission.REQUEST_APP_PERMISSION)
val fullscreen = NeoPreference.loadBoolean(R.string.key_ui_fullscreen, false)
diff --git a/app/src/main/java/io/neoterm/ui/customization/CustomizationActivity.kt b/app/src/main/java/io/neoterm/ui/customization/CustomizationActivity.kt
index 0dbf4b9..56a3183 100644
--- a/app/src/main/java/io/neoterm/ui/customization/CustomizationActivity.kt
+++ b/app/src/main/java/io/neoterm/ui/customization/CustomizationActivity.kt
@@ -4,9 +4,14 @@ import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.view.MenuItem
+import android.view.View
+import android.widget.AdapterView
+import android.widget.ArrayAdapter
+import android.widget.Spinner
import io.neoterm.R
import io.neoterm.backend.TerminalSession
import io.neoterm.customize.NeoTermPath
+import io.neoterm.customize.font.FontManager
import io.neoterm.utils.TerminalUtils
import io.neoterm.view.BasicSessionCallback
import io.neoterm.view.BasicViewClient
@@ -35,6 +40,26 @@ class CustomizationActivity: AppCompatActivity() {
session = TerminalUtils.createSession(this, "${NeoTermPath.USR_PATH}/bin/applets/echo",
arrayOf("echo", "Hello NeoTerm."), null, null, sessionCallback, false)
terminalView.attachSession(session)
+
+ setupSpinner(R.id.custom_font_spinner, FontManager.getFontNames(), FontManager.getCurrentFontName(), object : AdapterView.OnItemSelectedListener {
+ override fun onNothingSelected(parent: AdapterView<*>?) {
+ }
+
+ override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
+ val fontName = parent!!.adapter!!.getItem(position) as String
+ terminalView.setTypeface(FontManager.getFont(fontName).getTypeFace())
+ FontManager.setCurrentFont(fontName)
+ }
+ })
+ }
+
+ private fun setupSpinner(id: Int, data: List, selected: String, listener: AdapterView.OnItemSelectedListener) {
+ val spinner = findViewById(id) as Spinner
+ val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, data)
+ adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
+ spinner.adapter = adapter
+ spinner.onItemSelectedListener = listener
+ spinner.setSelection(if (data.contains(selected)) data.indexOf(selected) else 0)
}
override fun onDestroy() {
diff --git a/app/src/main/java/io/neoterm/utils/TerminalUtils.kt b/app/src/main/java/io/neoterm/utils/TerminalUtils.kt
index 57ad46f..3afa26b 100644
--- a/app/src/main/java/io/neoterm/utils/TerminalUtils.kt
+++ b/app/src/main/java/io/neoterm/utils/TerminalUtils.kt
@@ -17,7 +17,7 @@ import java.io.File
object TerminalUtils {
fun setupTerminalView(terminalView: TerminalView, terminalViewClient: BasicViewClient? = null) {
terminalView.textSize = NeoPreference.loadInt(NeoPreference.KEY_FONT_SIZE, 30)
- terminalView.setTypeface(FontManager.getCurrentFont().typeface)
+ terminalView.setTypeface(FontManager.getCurrentFont().getTypeFace())
if (terminalViewClient != null) {
terminalView.setOnKeyListener(terminalViewClient)
}
diff --git a/app/src/main/java/io/neoterm/view/ExtraKeysView.java b/app/src/main/java/io/neoterm/view/ExtraKeysView.java
index d27c855..373d7df 100755
--- a/app/src/main/java/io/neoterm/view/ExtraKeysView.java
+++ b/app/src/main/java/io/neoterm/view/ExtraKeysView.java
@@ -185,7 +185,7 @@ public final class ExtraKeysView extends LinearLayout {
button = new Button(getContext(), null, android.R.attr.buttonBarButtonStyle);
}
- button.setTypeface(FontManager.INSTANCE.getCurrentFont().getTypeface());
+ button.setTypeface(FontManager.INSTANCE.getCurrentFont().getTypeFace());
button.setText(extraButton.buttonText);
button.setTextColor(NORMAL_TEXT_COLOR);
button.setAllCaps(false);
diff --git a/app/src/main/res/layout/ui_customization.xml b/app/src/main/res/layout/ui_customization.xml
index 0b76d45..728be48 100644
--- a/app/src/main/res/layout/ui_customization.xml
+++ b/app/src/main/res/layout/ui_customization.xml
@@ -20,28 +20,42 @@
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="@dimen/text_margin"
- android:orientation="horizontal">
+ android:orientation="vertical">
-
+
-
+
+
+
+
+
+
+
+
+
+
+
-
软件源
向下切换窗口
关闭当前窗口时切换到下一个窗口而不是上一个
- 字体 & 主题 & 拓展键盘
- 个性化
+ 字体,主题,拓展键盘
+ 个性化
全屏
隐藏标题栏
键盘显示时隐藏标题栏
@@ -47,7 +47,7 @@
软件包: %s\n版本: %s\n依赖: %s\n占用空间: %s\n描述: %s\n主页: %s
软件包列表为空,请检查你的软件源
刷新
- 更新 & 刷新
+ 更新, 刷新
- 只使用 NeoTerm
@@ -63,4 +63,7 @@
- 输入…
拓展键盘
+ 响铃,振动,Shell
+ 全屏,标题栏,快捷键盘
+ 源,更新,升级
\ No newline at end of file
diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml
index 31cb4d7..12fbb6f 100644
--- a/app/src/main/res/values/preference_keys.xml
+++ b/app/src/main/res/values/preference_keys.xml
@@ -8,11 +8,12 @@
neoterm_ui_fullscreen
neoterm_ui_hide_toolbar
- neoterm_ui_font
- neoterm_ui_color_scheme
neoterm_ui_next_tab_anim
neoterm_ui_suggestions
neoterm_ui_wide_char_explicit
neoterm_package_source
+
+ neoterm_ui_font
+ neoterm_ui_color_scheme
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index a055e09..700639c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -10,8 +10,13 @@
About
Settings
General Settings
+ Bell, Vibrate, Shell
UI Settings
+ FullScreen, Title Bar, Suggestions
Package Settings
+ Source, Updates, Upgrades
+ Font, ColorScheme, ExtraKeys
+ Customization
Installing
You may install zsh and setup suggestions by executing: ~/install-zsh.sh
@@ -26,8 +31,6 @@
Which shell should we use when login
Program Selection
When both Neo Term and your Android OS have a program, which one should we choose?
- Font & ColorScheme & ExtraKeys
- Customization
Full Screen
Hide Toolbar
Hide toolbar when keyboard is showing
@@ -54,7 +57,7 @@
Package: %s\nVersion: %s\nDepends: %s\nInstalled Size: %s\nDescription: %s\nHome Page: %s
Package list is empty, please check out your source.
Refresh
- Update & Refresh
+ Update, Refresh
- sh
diff --git a/app/src/main/res/xml/settings_main.xml b/app/src/main/res/xml/settings_main.xml
index 68b8c47..2823d1a 100644
--- a/app/src/main/res/xml/settings_main.xml
+++ b/app/src/main/res/xml/settings_main.xml
@@ -3,6 +3,7 @@
+
+
+
+
-
-
-
-
-