Fix: Animation improvement

This commit is contained in:
zt515 2017-06-12 17:51:47 +08:00
parent 352684d831
commit ba712a7abf
3 changed files with 39 additions and 2 deletions

View File

@ -10,6 +10,8 @@ import android.support.v4.view.OnApplyWindowInsetsListener
import android.support.v4.view.ViewCompat
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.util.Log
import android.view.KeyEvent
import android.view.View
import android.widget.ImageButton
import de.mrapp.android.tabswitcher.*
@ -93,6 +95,7 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection {
}
override fun onTabRemoved(tabSwitcher: TabSwitcher, index: Int, tab: Tab, animation: Animation) {
Log.e("NeoTerm", "onTabRemoved " + tab.toString())
if (tab is TermTab) {
tab.termSession?.finishIfRunning()
removeFinishedSession(tab.termSession)
@ -121,6 +124,18 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection {
unbindService(this)
}
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
when (keyCode) {
KeyEvent.KEYCODE_BACK -> {
if (event?.action == KeyEvent.ACTION_DOWN && tabSwitcher.isSwitcherShown && tabSwitcher.count > 0) {
tabSwitcher.hideSwitcher()
return true
}
}
}
return super.onKeyDown(keyCode, event)
}
private fun addNewSession(session: TerminalSession?) {
if (session == null) {
return
@ -211,6 +226,14 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection {
R.id.menu_item_settings -> {
true
}
R.id.menu_item_new_session -> {
if (!tabSwitcher.isSwitcherShown) {
tabSwitcher.showSwitcher()
}
val index = tabSwitcher.count
addNewSession("NeoTerm #" + index, createRevealAnimation())
true
}
else -> false
}
}
@ -220,9 +243,17 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection {
val tab = TermTab(tabTitle ?: "NeoTerm")
tab.closeTabProvider = object : CloseTabProvider {
override fun closeTab(tab: Tab) {
// FIXME: No Such Tab
tabSwitcher.showSwitcher()
tabSwitcher.removeTab(tab)
if (tabSwitcher.count > 0) {
switchToSession(tabSwitcher.getTab(tabSwitcher.count - 1))
if (tabSwitcher.count > 1) {
var index = tabSwitcher.indexOf(tab)
// 关闭当前窗口后,向上一个窗口切换
if (++index >= tabSwitcher.count) index = 0
// 关闭当前窗口后,向下一个窗口切换
// if (--index < 0) index = tabSwitcher.count - 1
switchToSession(tabSwitcher.getTab(index))
}
}
}

View File

@ -22,6 +22,11 @@ License.
app:actionLayout="@layout/tab_switcher_menu_item"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/menu_item_new_session"
android:title="@string/new_session"
app:showAsAction="never"/>
<item
android:id="@+id/menu_item_settings"
android:title="@string/menu_settings"

View File

@ -6,4 +6,5 @@
<string name="toggle_tab_switcher_menu_item">Toggle switcher</string>
<string name="menu_settings">Settings</string>
<string name="new_session">New session</string>
</resources>