Fix: Crash when running in background.
This commit is contained in:
@ -17,8 +17,8 @@ android {
|
|||||||
applicationId "io.neoterm"
|
applicationId "io.neoterm"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 25
|
targetSdkVersion 25
|
||||||
versionCode 9
|
versionCode 10
|
||||||
versionName "1.1.7"
|
versionName "1.1.8"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
resConfigs "zh"
|
resConfigs "zh"
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
|
@ -3,6 +3,7 @@ package io.neoterm
|
|||||||
import android.app.Application
|
import android.app.Application
|
||||||
import io.neoterm.customize.color.ColorSchemeManager
|
import io.neoterm.customize.color.ColorSchemeManager
|
||||||
import io.neoterm.customize.font.FontManager
|
import io.neoterm.customize.font.FontManager
|
||||||
|
import io.neoterm.preference.NeoPreference
|
||||||
import io.neoterm.utils.CrashHandler
|
import io.neoterm.utils.CrashHandler
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,6 +13,7 @@ class App : Application() {
|
|||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
app = this
|
app = this
|
||||||
|
NeoPreference.init(this)
|
||||||
CrashHandler.init()
|
CrashHandler.init()
|
||||||
|
|
||||||
// ensure that we can access these any time
|
// ensure that we can access these any time
|
||||||
|
@ -22,11 +22,11 @@ object NeoPermission {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ContextCompat.checkSelfPermission(context,
|
if (ContextCompat.checkSelfPermission(context,
|
||||||
Manifest.permission.READ_CONTACTS)
|
Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||||
!= PackageManager.PERMISSION_GRANTED) {
|
!= PackageManager.PERMISSION_GRANTED) {
|
||||||
|
|
||||||
if (ActivityCompat.shouldShowRequestPermissionRationale(context,
|
if (ActivityCompat.shouldShowRequestPermissionRationale(context,
|
||||||
Manifest.permission.READ_CONTACTS)) {
|
Manifest.permission.READ_EXTERNAL_STORAGE)) {
|
||||||
AlertDialog.Builder(context).setMessage("需要存储权限来访问存储设备上的文件")
|
AlertDialog.Builder(context).setMessage("需要存储权限来访问存储设备上的文件")
|
||||||
.setPositiveButton(android.R.string.ok, { _: DialogInterface, _: Int ->
|
.setPositiveButton(android.R.string.ok, { _: DialogInterface, _: Int ->
|
||||||
doRequestPermission(context, requestCode)
|
doRequestPermission(context, requestCode)
|
||||||
|
@ -42,10 +42,6 @@ object NeoPreference {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun cleanup() {
|
|
||||||
preference = null
|
|
||||||
}
|
|
||||||
|
|
||||||
fun store(key: Int, value: Any) {
|
fun store(key: Int, value: Any) {
|
||||||
store(App.get().getString(key), value)
|
store(App.get().getString(key), value)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package io.neoterm.ui.term
|
package io.neoterm.ui.term
|
||||||
|
|
||||||
import android.animation.ObjectAnimator
|
import android.animation.ObjectAnimator
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.AlertDialog
|
import android.app.AlertDialog
|
||||||
import android.content.*
|
import android.content.*
|
||||||
@ -37,6 +38,7 @@ import io.neoterm.ui.term.tab.TermTab
|
|||||||
import io.neoterm.ui.term.tab.TermTabDecorator
|
import io.neoterm.ui.term.tab.TermTabDecorator
|
||||||
import io.neoterm.ui.term.tab.TermViewClient
|
import io.neoterm.ui.term.tab.TermViewClient
|
||||||
import io.neoterm.ui.term.tab.event.TabCloseEvent
|
import io.neoterm.ui.term.tab.event.TabCloseEvent
|
||||||
|
import io.neoterm.ui.term.tab.event.TitleChangedEvent
|
||||||
import io.neoterm.ui.term.tab.event.ToggleFullScreenEvent
|
import io.neoterm.ui.term.tab.event.ToggleFullScreenEvent
|
||||||
import io.neoterm.utils.FullScreenHelper
|
import io.neoterm.utils.FullScreenHelper
|
||||||
import io.neoterm.view.eks.StatedControlButton
|
import io.neoterm.view.eks.StatedControlButton
|
||||||
@ -65,7 +67,7 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
|
|||||||
|
|
||||||
ColorSchemeManager.init(this)
|
ColorSchemeManager.init(this)
|
||||||
FontManager.init(this)
|
FontManager.init(this)
|
||||||
NeoPreference.init(this)
|
// NeoPreference.init(this)
|
||||||
NeoPermission.initAppPermission(this, NeoPermission.REQUEST_APP_PERMISSION)
|
NeoPermission.initAppPermission(this, NeoPermission.REQUEST_APP_PERMISSION)
|
||||||
|
|
||||||
val fullscreen = NeoPreference.loadBoolean(R.string.key_ui_fullscreen, false)
|
val fullscreen = NeoPreference.loadBoolean(R.string.key_ui_fullscreen, false)
|
||||||
@ -121,9 +123,9 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
|
|||||||
val tab = tabSwitcher.selectedTab as TermTab
|
val tab = tabSwitcher.selectedTab as TermTab
|
||||||
tab.requireHideIme()
|
tab.requireHideIme()
|
||||||
}
|
}
|
||||||
toggleSwitcher(showSwitcher = true)
|
toggleSwitcher(showSwitcher = true, easterEgg = true)
|
||||||
} else {
|
} else {
|
||||||
toggleSwitcher(showSwitcher = false)
|
toggleSwitcher(showSwitcher = false, easterEgg = true)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return true
|
return true
|
||||||
@ -152,7 +154,7 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
|
|||||||
}
|
}
|
||||||
R.id.menu_item_new_session -> {
|
R.id.menu_item_new_session -> {
|
||||||
if (!tabSwitcher.isSwitcherShown) {
|
if (!tabSwitcher.isSwitcherShown) {
|
||||||
toggleSwitcher(showSwitcher = true)
|
toggleSwitcher(showSwitcher = true, easterEgg = false)
|
||||||
}
|
}
|
||||||
val index = tabSwitcher.count
|
val index = tabSwitcher.count
|
||||||
addNewSession("NeoTerm #" + index, systemShell, createRevealAnimation())
|
addNewSession("NeoTerm #" + index, systemShell, createRevealAnimation())
|
||||||
@ -228,14 +230,13 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
|
|||||||
termService = null
|
termService = null
|
||||||
}
|
}
|
||||||
unbindService(this)
|
unbindService(this)
|
||||||
NeoPreference.cleanup()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||||
when (keyCode) {
|
when (keyCode) {
|
||||||
KeyEvent.KEYCODE_BACK -> {
|
KeyEvent.KEYCODE_BACK -> {
|
||||||
if (event?.action == KeyEvent.ACTION_DOWN && tabSwitcher.isSwitcherShown && tabSwitcher.count > 0) {
|
if (event?.action == KeyEvent.ACTION_DOWN && tabSwitcher.isSwitcherShown && tabSwitcher.count > 0) {
|
||||||
toggleSwitcher(showSwitcher = false)
|
toggleSwitcher(showSwitcher = false, easterEgg = false)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -314,7 +315,7 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun enterSystemShell() {
|
private fun enterSystemShell() {
|
||||||
toggleSwitcher(showSwitcher = true)
|
toggleSwitcher(showSwitcher = true, easterEgg = false)
|
||||||
addNewSession("NeoTerm #0", systemShell, createRevealAnimation())
|
addNewSession("NeoTerm #0", systemShell, createRevealAnimation())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,7 +328,7 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
|
|||||||
}
|
}
|
||||||
switchToSession(getStoredCurrentSessionOrLast())
|
switchToSession(getStoredCurrentSessionOrLast())
|
||||||
} else {
|
} else {
|
||||||
toggleSwitcher(showSwitcher = true)
|
toggleSwitcher(showSwitcher = true, easterEgg = false)
|
||||||
addNewSession("NeoTerm #0", systemShell, createRevealAnimation())
|
addNewSession("NeoTerm #0", systemShell, createRevealAnimation())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -502,18 +503,21 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleSwitcher(showSwitcher: Boolean) {
|
private fun toggleSwitcher(showSwitcher: Boolean, easterEgg: Boolean) {
|
||||||
if (tabSwitcher.count > 0) {
|
if (tabSwitcher.count > 0) {
|
||||||
val transparentAnimator = ObjectAnimator.ofFloat(toolbar, View.ALPHA, 1.0f, 0.0f, 1.0f)
|
if (showSwitcher) {
|
||||||
transparentAnimator.interpolator = AccelerateDecelerateInterpolator()
|
val transparentAnimator = ObjectAnimator.ofFloat(toolbar, View.ALPHA, 1.0f, 0.0f, 1.0f)
|
||||||
transparentAnimator.start()
|
transparentAnimator.interpolator = AccelerateDecelerateInterpolator()
|
||||||
} else {
|
transparentAnimator.start()
|
||||||
|
}
|
||||||
|
} else if (easterEgg) {
|
||||||
val happyCount = NeoPreference.loadInt(NeoPreference.KEY_HAPPY_EGG, 0) + 1
|
val happyCount = NeoPreference.loadInt(NeoPreference.KEY_HAPPY_EGG, 0) + 1
|
||||||
NeoPreference.store(NeoPreference.KEY_HAPPY_EGG, happyCount)
|
NeoPreference.store(NeoPreference.KEY_HAPPY_EGG, happyCount)
|
||||||
|
|
||||||
val trigger = NeoPreference.VALUE_HAPPY_EGG_TRIGGER
|
val trigger = NeoPreference.VALUE_HAPPY_EGG_TRIGGER
|
||||||
|
|
||||||
if (happyCount == trigger / 2) {
|
if (happyCount == trigger / 2) {
|
||||||
|
@SuppressLint("ShowToast")
|
||||||
val toast = Toast.makeText(this, "Emm...", Toast.LENGTH_LONG)
|
val toast = Toast.makeText(this, "Emm...", Toast.LENGTH_LONG)
|
||||||
toast.setGravity(Gravity.CENTER, 0, 0)
|
toast.setGravity(Gravity.CENTER, 0, 0)
|
||||||
toast.show()
|
toast.show()
|
||||||
@ -534,7 +538,7 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
|
|||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
fun onTabCloseEvent(tabCloseEvent: TabCloseEvent) {
|
fun onTabCloseEvent(tabCloseEvent: TabCloseEvent) {
|
||||||
val tab = tabCloseEvent.termTab
|
val tab = tabCloseEvent.termTab
|
||||||
toggleSwitcher(showSwitcher = true)
|
toggleSwitcher(showSwitcher = true, easterEgg = false)
|
||||||
tabSwitcher.removeTab(tab)
|
tabSwitcher.removeTab(tab)
|
||||||
|
|
||||||
if (tabSwitcher.count > 1) {
|
if (tabSwitcher.count > 1) {
|
||||||
@ -556,4 +560,14 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
|
|||||||
val fullScreen = fullScreenHelper.fullScreen
|
val fullScreen = fullScreenHelper.fullScreen
|
||||||
setFullScreenMode(!fullScreen)
|
setFullScreenMode(!fullScreen)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Suppress("unused", "UNUSED_PARAMETER")
|
||||||
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
|
fun onTitleChangedEvent(titleChangedEvent: TitleChangedEvent) {
|
||||||
|
if (!tabSwitcher.isSwitcherShown) {
|
||||||
|
toolbar.title = titleChangedEvent.title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import io.neoterm.backend.TerminalSession
|
|||||||
import io.neoterm.customize.color.ColorSchemeManager
|
import io.neoterm.customize.color.ColorSchemeManager
|
||||||
import io.neoterm.preference.NeoPreference
|
import io.neoterm.preference.NeoPreference
|
||||||
import io.neoterm.ui.term.tab.event.TabCloseEvent
|
import io.neoterm.ui.term.tab.event.TabCloseEvent
|
||||||
|
import io.neoterm.ui.term.tab.event.TitleChangedEvent
|
||||||
import io.neoterm.ui.term.tab.event.ToggleFullScreenEvent
|
import io.neoterm.ui.term.tab.event.ToggleFullScreenEvent
|
||||||
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.EventBus
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ class TermTab(title: CharSequence) : Tab(title) {
|
|||||||
fun updateTitle(title: String) {
|
fun updateTitle(title: String) {
|
||||||
if (title.isNotEmpty()) {
|
if (title.isNotEmpty()) {
|
||||||
this.title = title
|
this.title = title
|
||||||
toolbar?.title = title
|
EventBus.getDefault().post(TitleChangedEvent(title))
|
||||||
if (NeoPreference.loadBoolean(R.string.key_ui_suggestions, true)) {
|
if (NeoPreference.loadBoolean(R.string.key_ui_suggestions, true)) {
|
||||||
viewClient?.updateSuggestions(title)
|
viewClient?.updateSuggestions(title)
|
||||||
} else {
|
} else {
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
package io.neoterm.ui.term.tab.event
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author kiva
|
||||||
|
*/
|
||||||
|
class TitleChangedEvent(val title: String)
|
@ -17,6 +17,8 @@ object CrashHandler : Thread.UncaughtExceptionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun uncaughtException(t: Thread?, e: Throwable?) {
|
override fun uncaughtException(t: Thread?, e: Throwable?) {
|
||||||
|
e?.printStackTrace()
|
||||||
|
|
||||||
val intent = Intent(App.get(), CrashActivity::class.java)
|
val intent = Intent(App.get(), CrashActivity::class.java)
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
intent.putExtra("exception", e)
|
intent.putExtra("exception", e)
|
||||||
|
Reference in New Issue
Block a user