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