Unverified Commit 2177abcd authored by Mygod's avatar Mygod Committed by GitHub

Immersive theme: Make navigation bars translucent (#2263)

parent f04106a4
...@@ -34,6 +34,7 @@ import android.os.Build ...@@ -34,6 +34,7 @@ import android.os.Build
import android.system.Os import android.system.Os
import android.system.OsConstants import android.system.OsConstants
import android.util.TypedValue import android.util.TypedValue
import android.view.WindowInsets
import androidx.annotation.AttrRes import androidx.annotation.AttrRes
import androidx.preference.Preference import androidx.preference.Preference
import com.crashlytics.android.Crashlytics import com.crashlytics.android.Crashlytics
...@@ -114,6 +115,10 @@ fun Resources.Theme.resolveResourceId(@AttrRes resId: Int): Int { ...@@ -114,6 +115,10 @@ fun Resources.Theme.resolveResourceId(@AttrRes resId: Int): Int {
val Intent.datas get() = listOfNotNull(data) + (clipData?.asIterable()?.mapNotNull { it.uri } ?: emptyList()) val Intent.datas get() = listOfNotNull(data) + (clipData?.asIterable()?.mapNotNull { it.uri } ?: emptyList())
@Suppress("DEPRECATION")
fun WindowInsets.consumeSystemWindowInsetTop() = replaceSystemWindowInsets(
systemWindowInsetLeft, 0, systemWindowInsetRight, systemWindowInsetBottom)
fun printLog(t: Throwable) { fun printLog(t: Throwable) {
Crashlytics.logException(t) Crashlytics.logException(t)
t.printStackTrace() t.printStackTrace()
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/Theme.Shadowsocks.Navigation" android:theme="@style/Theme.Shadowsocks.Immersive.Navigation"
android:launchMode="singleTop"> android:launchMode="singleTop">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
<activity <activity
android:name=".ProfileConfigActivity" android:name=".ProfileConfigActivity"
android:theme="@style/Theme.Shadowsocks.Immersive"
android:excludeFromRecents="true" android:excludeFromRecents="true"
android:label="@string/profile_config"/> android:label="@string/profile_config"/>
...@@ -40,11 +41,13 @@ ...@@ -40,11 +41,13 @@
android:name=".AppManager" android:name=".AppManager"
android:label="@string/proxied_apps" android:label="@string/proxied_apps"
android:parentActivityName=".ProfileConfigActivity" android:parentActivityName=".ProfileConfigActivity"
android:theme="@style/Theme.Shadowsocks.Immersive"
android:excludeFromRecents="true"/> android:excludeFromRecents="true"/>
<activity <activity
android:name=".UdpFallbackProfileActivity" android:name=".UdpFallbackProfileActivity"
android:label="@string/udp_fallback" android:label="@string/udp_fallback"
android:theme="@style/Theme.Shadowsocks.Immersive"
android:excludeFromRecents="true"/> android:excludeFromRecents="true"/>
<activity <activity
...@@ -54,7 +57,7 @@ ...@@ -54,7 +57,7 @@
android:excludeFromRecents="true"/> android:excludeFromRecents="true"/>
<activity android:name=".tasker.ConfigActivity" <activity android:name=".tasker.ConfigActivity"
android:icon="@mipmap/ic_launcher"> android:theme="@style/Theme.Shadowsocks.Immersive">
<intent-filter> <intent-filter>
<action android:name="com.twofortyfouram.locale.intent.action.EDIT_SETTING" /> <action android:name="com.twofortyfouram.locale.intent.action.EDIT_SETTING" />
</intent-filter> </intent-filter>
...@@ -72,7 +75,8 @@ ...@@ -72,7 +75,8 @@
</intent-filter> </intent-filter>
</activity> </activity>
<service android:name=".bg.TileService" android:label="@string/quick_toggle" <service android:name=".bg.TileService"
android:label="@string/quick_toggle"
android:process=":bg" android:process=":bg"
android:directBootAware="true" android:directBootAware="true"
android:icon="@drawable/ic_service_active" android:icon="@drawable/ic_service_active"
......
...@@ -42,6 +42,8 @@ import androidx.annotation.UiThread ...@@ -42,6 +42,8 @@ import androidx.annotation.UiThread
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
import androidx.core.util.set import androidx.core.util.set
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding
import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
...@@ -51,6 +53,7 @@ import com.github.shadowsocks.preference.DataStore ...@@ -51,6 +53,7 @@ import com.github.shadowsocks.preference.DataStore
import com.github.shadowsocks.utils.DirectBoot import com.github.shadowsocks.utils.DirectBoot
import com.github.shadowsocks.utils.Key import com.github.shadowsocks.utils.Key
import com.github.shadowsocks.utils.SingleInstanceActivity import com.github.shadowsocks.utils.SingleInstanceActivity
import com.github.shadowsocks.utils.consumeSystemWindowInsetTop
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.layout_apps.* import kotlinx.android.synthetic.main.layout_apps.*
import kotlinx.android.synthetic.main.layout_apps_item.view.* import kotlinx.android.synthetic.main.layout_apps_item.view.*
...@@ -212,6 +215,10 @@ class AppManager : AppCompatActivity() { ...@@ -212,6 +215,10 @@ class AppManager : AppCompatActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
SingleInstanceActivity.register(this) ?: return SingleInstanceActivity.register(this) ?: return
setContentView(R.layout.layout_apps) setContentView(R.layout.layout_apps)
findViewById<View>(android.R.id.content).setOnApplyWindowInsetsListener { v, insets ->
v.updateLayoutParams<ViewGroup.MarginLayoutParams> { topMargin += insets.systemWindowInsetTop }
insets.consumeSystemWindowInsetTop()
}
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
supportActionBar!!.setDisplayHomeAsUpEnabled(true) supportActionBar!!.setDisplayHomeAsUpEnabled(true)
...@@ -234,6 +241,10 @@ class AppManager : AppCompatActivity() { ...@@ -234,6 +241,10 @@ class AppManager : AppCompatActivity() {
} }
initProxiedUids() initProxiedUids()
list.setOnApplyWindowInsetsListener { v, insets ->
v.updatePadding(bottom = v.paddingBottom + insets.systemWindowInsetBottom)
insets.consumeSystemWindowInsets()
}
list.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false) list.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false)
list.itemAnimator = DefaultItemAnimator() list.itemAnimator = DefaultItemAnimator()
list.adapter = appsAdapter list.adapter = appsAdapter
......
...@@ -26,13 +26,17 @@ import android.content.Intent ...@@ -26,13 +26,17 @@ import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.updateLayoutParams
import com.github.shadowsocks.plugin.AlertDialogFragment import com.github.shadowsocks.plugin.AlertDialogFragment
import com.github.shadowsocks.plugin.Empty import com.github.shadowsocks.plugin.Empty
import com.github.shadowsocks.plugin.PluginContract import com.github.shadowsocks.plugin.PluginContract
import com.github.shadowsocks.preference.DataStore import com.github.shadowsocks.preference.DataStore
import com.github.shadowsocks.utils.SingleInstanceActivity import com.github.shadowsocks.utils.SingleInstanceActivity
import com.github.shadowsocks.utils.consumeSystemWindowInsetTop
class ProfileConfigActivity : AppCompatActivity() { class ProfileConfigActivity : AppCompatActivity() {
companion object { companion object {
...@@ -54,6 +58,10 @@ class ProfileConfigActivity : AppCompatActivity() { ...@@ -54,6 +58,10 @@ class ProfileConfigActivity : AppCompatActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
SingleInstanceActivity.register(this) ?: return SingleInstanceActivity.register(this) ?: return
setContentView(R.layout.layout_profile_config) setContentView(R.layout.layout_profile_config)
findViewById<View>(android.R.id.content).setOnApplyWindowInsetsListener { v, insets ->
v.updateLayoutParams<ViewGroup.MarginLayoutParams> { topMargin += insets.systemWindowInsetTop }
insets.consumeSystemWindowInsetTop()
}
setSupportActionBar(findViewById(R.id.toolbar)) setSupportActionBar(findViewById(R.id.toolbar))
supportActionBar!!.apply { supportActionBar!!.apply {
setDisplayHomeAsUpEnabled(true) setDisplayHomeAsUpEnabled(true)
......
...@@ -28,7 +28,9 @@ import android.os.Build ...@@ -28,7 +28,9 @@ import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Parcelable import android.os.Parcelable
import android.view.MenuItem import android.view.MenuItem
import android.view.View
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.view.updatePadding
import androidx.preference.* import androidx.preference.*
import com.github.shadowsocks.Core.app import com.github.shadowsocks.Core.app
import com.github.shadowsocks.database.Profile import com.github.shadowsocks.database.Profile
...@@ -112,6 +114,14 @@ class ProfileConfigFragment : PreferenceFragmentCompat(), ...@@ -112,6 +114,14 @@ class ProfileConfigFragment : PreferenceFragmentCompat(),
DataStore.privateStore.registerChangeListener(this) DataStore.privateStore.registerChangeListener(this)
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
listView.setOnApplyWindowInsetsListener { v, insets ->
v.updatePadding(bottom = v.paddingBottom + insets.systemWindowInsetBottom)
insets.consumeSystemWindowInsets()
}
}
private fun initPlugins() { private fun initPlugins() {
val plugins = PluginManager.fetchPlugins() val plugins = PluginManager.fetchPlugins()
plugin.entries = plugins.map { it.value.label }.toTypedArray() plugin.entries = plugins.map { it.value.label }.toTypedArray()
......
...@@ -28,6 +28,8 @@ import android.view.ViewGroup ...@@ -28,6 +28,8 @@ import android.view.ViewGroup
import android.widget.CheckedTextView import android.widget.CheckedTextView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding
import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
...@@ -36,6 +38,7 @@ import com.github.shadowsocks.database.ProfileManager ...@@ -36,6 +38,7 @@ import com.github.shadowsocks.database.ProfileManager
import com.github.shadowsocks.plugin.PluginConfiguration import com.github.shadowsocks.plugin.PluginConfiguration
import com.github.shadowsocks.preference.DataStore import com.github.shadowsocks.preference.DataStore
import com.github.shadowsocks.utils.SingleInstanceActivity import com.github.shadowsocks.utils.SingleInstanceActivity
import com.github.shadowsocks.utils.consumeSystemWindowInsetTop
import com.github.shadowsocks.utils.resolveResourceId import com.github.shadowsocks.utils.resolveResourceId
class UdpFallbackProfileActivity : AppCompatActivity() { class UdpFallbackProfileActivity : AppCompatActivity() {
...@@ -85,18 +88,28 @@ class UdpFallbackProfileActivity : AppCompatActivity() { ...@@ -85,18 +88,28 @@ class UdpFallbackProfileActivity : AppCompatActivity() {
} }
SingleInstanceActivity.register(this) ?: return SingleInstanceActivity.register(this) ?: return
setContentView(R.layout.layout_udp_fallback) setContentView(R.layout.layout_udp_fallback)
findViewById<View>(android.R.id.content).setOnApplyWindowInsetsListener { v, insets ->
v.updateLayoutParams<ViewGroup.MarginLayoutParams> { topMargin += insets.systemWindowInsetTop }
insets.consumeSystemWindowInsetTop()
}
val toolbar = findViewById<Toolbar>(R.id.toolbar) val toolbar = findViewById<Toolbar>(R.id.toolbar)
toolbar.setTitle(R.string.udp_fallback) toolbar.setTitle(R.string.udp_fallback)
toolbar.setNavigationIcon(R.drawable.ic_navigation_close) toolbar.setNavigationIcon(R.drawable.ic_navigation_close)
toolbar.setNavigationOnClickListener { finish() } toolbar.setNavigationOnClickListener { finish() }
val profilesList = findViewById<RecyclerView>(R.id.list) findViewById<RecyclerView>(R.id.list).apply {
val lm = LinearLayoutManager(this, RecyclerView.VERTICAL, false) setOnApplyWindowInsetsListener { v, insets ->
profilesList.layoutManager = lm v.updatePadding(bottom = v.paddingBottom + insets.systemWindowInsetBottom)
profilesList.itemAnimator = DefaultItemAnimator() insets.consumeSystemWindowInsets()
profilesList.adapter = profilesAdapter }
if (DataStore.udpFallback != null) itemAnimator = DefaultItemAnimator()
lm.scrollToPosition(profilesAdapter.profiles.indexOfFirst { it.id == DataStore.udpFallback } + 1) adapter = profilesAdapter
layoutManager = LinearLayoutManager(this@UdpFallbackProfileActivity, RecyclerView.VERTICAL, false).apply {
if (DataStore.udpFallback != null) {
scrollToPosition(profilesAdapter.profiles.indexOfFirst { it.id == DataStore.udpFallback } + 1)
}
}
}
} }
} }
...@@ -30,12 +30,15 @@ import android.widget.CheckedTextView ...@@ -30,12 +30,15 @@ import android.widget.CheckedTextView
import android.widget.Switch import android.widget.Switch
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding
import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.github.shadowsocks.R import com.github.shadowsocks.R
import com.github.shadowsocks.database.Profile import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.database.ProfileManager import com.github.shadowsocks.database.ProfileManager
import com.github.shadowsocks.utils.consumeSystemWindowInsetTop
import com.github.shadowsocks.utils.resolveResourceId import com.github.shadowsocks.utils.resolveResourceId
class ConfigActivity : AppCompatActivity() { class ConfigActivity : AppCompatActivity() {
...@@ -92,6 +95,10 @@ class ConfigActivity : AppCompatActivity() { ...@@ -92,6 +95,10 @@ class ConfigActivity : AppCompatActivity() {
} }
taskerOption = Settings.fromIntent(intent) taskerOption = Settings.fromIntent(intent)
setContentView(R.layout.layout_tasker) setContentView(R.layout.layout_tasker)
findViewById<View>(android.R.id.content).setOnApplyWindowInsetsListener { v, insets ->
v.updateLayoutParams<ViewGroup.MarginLayoutParams> { topMargin += insets.systemWindowInsetTop }
insets.consumeSystemWindowInsetTop()
}
val toolbar = findViewById<Toolbar>(R.id.toolbar) val toolbar = findViewById<Toolbar>(R.id.toolbar)
toolbar.setTitle(R.string.app_name) toolbar.setTitle(R.string.app_name)
...@@ -100,12 +107,18 @@ class ConfigActivity : AppCompatActivity() { ...@@ -100,12 +107,18 @@ class ConfigActivity : AppCompatActivity() {
switch = findViewById(R.id.serviceSwitch) switch = findViewById(R.id.serviceSwitch)
switch.isChecked = taskerOption.switchOn switch.isChecked = taskerOption.switchOn
val profilesList = findViewById<RecyclerView>(R.id.list) findViewById<RecyclerView>(R.id.list).apply {
val lm = LinearLayoutManager(this, RecyclerView.VERTICAL, false) setOnApplyWindowInsetsListener { v, insets ->
profilesList.layoutManager = lm v.updatePadding(bottom = v.paddingBottom + insets.systemWindowInsetBottom)
profilesList.itemAnimator = DefaultItemAnimator() insets.consumeSystemWindowInsets()
profilesList.adapter = profilesAdapter }
if (taskerOption.profileId >= 0) itemAnimator = DefaultItemAnimator()
lm.scrollToPosition(profilesAdapter.profiles.indexOfFirst { it.id == taskerOption.profileId } + 1) adapter = profilesAdapter
layoutManager = LinearLayoutManager(this@ConfigActivity, RecyclerView.VERTICAL, false).apply {
if (taskerOption.profileId >= 0) {
scrollToPosition(profilesAdapter.profiles.indexOfFirst { it.id == taskerOption.profileId } + 1)
}
}
}
} }
} }
...@@ -94,6 +94,7 @@ ...@@ -94,6 +94,7 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:id="@+id/list" android:id="@+id/list"
android:clipToPadding="false"
android:visibility="gone" android:visibility="gone"
app:fastScrollEnabled="true" app:fastScrollEnabled="true"
app:fastScrollHorizontalThumbDrawable="@drawable/fastscroll_thumb" app:fastScrollHorizontalThumbDrawable="@drawable/fastscroll_thumb"
......
...@@ -6,13 +6,14 @@ ...@@ -6,13 +6,14 @@
android:id="@+id/drawer" android:id="@+id/drawer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/color_primary"
android:fitsSystemWindows="true"> android:fitsSystemWindows="true">
<androidx.coordinatorlayout.widget.CoordinatorLayout <androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/snackbar" android:id="@+id/snackbar"
android:background="?android:attr/windowBackground"
android:clipChildren="false" android:clipChildren="false"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:fitsSystemWindows="true">
<FrameLayout <FrameLayout
android:id="@+id/fragment_holder" android:id="@+id/fragment_holder"
...@@ -127,7 +128,6 @@ ...@@ -127,7 +128,6 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="start" android:layout_gravity="start"
android:fitsSystemWindows="true"
app:itemIconTint="@color/nav_item_tint" app:itemIconTint="@color/nav_item_tint"
app:itemTextColor="@color/nav_item_tint" app:itemTextColor="@color/nav_item_tint"
app:headerLayout="@layout/navigation_header" app:headerLayout="@layout/navigation_header"
......
...@@ -16,9 +16,11 @@ ...@@ -16,9 +16,11 @@
android:textSize="18sp" android:textSize="18sp"
android:padding="16dp"/> android:padding="16dp"/>
</FrameLayout> </FrameLayout>
<androidx.recyclerview.widget.RecyclerView android:id="@+id/list" <androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent" android:id="@+id/list"
android:layout_height="match_parent" android:layout_width="match_parent"
tools:itemview="@android:layout/select_dialog_singlechoice_material" android:layout_height="match_parent"
android:scrollbars="vertical"/> android:clipToPadding="false"
android:scrollbars="vertical"
tools:itemview="@android:layout/select_dialog_singlechoice_material"/>
</LinearLayout> </LinearLayout>
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<androidx.recyclerview.widget.RecyclerView android:id="@+id/list" <androidx.recyclerview.widget.RecyclerView android:id="@+id/list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:clipToPadding="false"
tools:itemview="@android:layout/select_dialog_singlechoice_material" tools:itemview="@android:layout/select_dialog_singlechoice_material"
android:scrollbars="vertical"/> android:scrollbars="vertical"/>
</LinearLayout> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<style name="Theme.Shadowsocks.Navigation"> <style name="Theme.Shadowsocks.Immersive.Navigation">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item> <item name="android:statusBarColor">@android:color/transparent</item>
</style> </style>
<style name="stats_status"> <style name="stats_status">
......
...@@ -9,6 +9,10 @@ ...@@ -9,6 +9,10 @@
<item name="colorPrimaryDark">@color/color_primary_dark</item> <item name="colorPrimaryDark">@color/color_primary_dark</item>
<item name="windowActionModeOverlay">true</item> <item name="windowActionModeOverlay">true</item>
</style> </style>
<style name="Theme.Shadowsocks.Immersive">
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
<style name="Theme.AppCompat.Translucent" parent="Theme.AppCompat.Dialog"> <style name="Theme.AppCompat.Translucent" parent="Theme.AppCompat.Dialog">
<item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowFrame">@null</item> <item name="android:windowFrame">@null</item>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment